This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
FYI: fix leak in convert_value_from_python
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 28 Feb 2011 12:38:19 -0700
- Subject: FYI: fix leak in convert_value_from_python
I'm checking this in.
While reviewing Phil's patch I happened across a memory leak in
convert_value_from_python. This patch fixes the problem by making the
string "value" a global constant.
Built and regtested on x86-64 (compile farm).
Tom
2011-02-28 Tom Tromey <tromey@redhat.com>
* python/python.c (gdbpy_value_cst): New global.
(_initialize_python): Initialize it.
* python/python-internal.h (gdbpy_value_cst): Declare.
* python/py-value.c (convert_value_from_python): Use
gdbpy_value_cst.
Index: python/py-value.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-value.c,v
retrieving revision 1.22
diff -u -r1.22 py-value.c
--- python/py-value.c 26 Feb 2011 02:07:09 -0000 1.22
+++ python/py-value.c 28 Feb 2011 19:36:46 -0000
@@ -1162,9 +1162,8 @@
else if (gdbpy_is_lazy_string (obj))
{
PyObject *result;
- PyObject *function = PyString_FromString ("value");
- result = PyObject_CallMethodObjArgs (obj, function, NULL);
+ result = PyObject_CallMethodObjArgs (obj, gdbpy_value_cst, NULL);
value = value_copy (((value_object *) result)->value);
}
else
Index: python/python-internal.h
===================================================================
RCS file: /cvs/src/src/gdb/python/python-internal.h,v
retrieving revision 1.43
diff -u -r1.43 python-internal.h
--- python/python-internal.h 22 Feb 2011 22:48:09 -0000 1.43
+++ python/python-internal.h 28 Feb 2011 19:36:46 -0000
@@ -271,6 +271,7 @@
extern PyObject *gdbpy_to_string_cst;
extern PyObject *gdbpy_display_hint_cst;
extern PyObject *gdbpy_enabled_cst;
+extern PyObject *gdbpy_value_cst;
/* Exception types. */
extern PyObject *gdbpy_gdb_error;
Index: python/python.c
===================================================================
RCS file: /cvs/src/src/gdb/python/python.c,v
retrieving revision 1.60
diff -u -r1.60 python.c
--- python/python.c 22 Feb 2011 22:48:09 -0000 1.60
+++ python/python.c 28 Feb 2011 19:36:46 -0000
@@ -62,6 +62,7 @@
PyObject *gdbpy_display_hint_cst;
PyObject *gdbpy_doc_cst;
PyObject *gdbpy_enabled_cst;
+PyObject *gdbpy_value_cst;
/* The GdbError exception. */
PyObject *gdbpy_gdberror_exc;
@@ -1015,6 +1016,7 @@
gdbpy_display_hint_cst = PyString_FromString ("display_hint");
gdbpy_doc_cst = PyString_FromString ("__doc__");
gdbpy_enabled_cst = PyString_FromString ("enabled");
+ gdbpy_value_cst = PyString_FromString ("value");
/* Release the GIL while gdb runs. */
PyThreadState_Swap (NULL);