This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [python] leaks from pretty printers


Paul Pluzhnikov wrote:

Hi Paul,

It looks like you are using --with-pymalloc python (the default),
and it looks like this many be preventing VG from accurate leak
detection.

Thanks for the tip. I rebuilt the Python RPM with: "--without-pymalloc"


Also, you probably would want to increase VG --num-callers parameter
from default 10, so you can see which parts of GDB are causing the
17336-byte possible leak


I ended up deciding to recreate your environment. I built the inferior listed in your email, rebuilt Python with similar options, and executed Valgrind in the same manner you executed it. I did replicate your results and I am studying them. I chatted with Tom a bit last night about one particular case, and this draft patch fixes that case and seals about 75% of the memory leak.

In case I missed something in my environment, can you please apply and test it for results? My results with the patch and following the 100 loops of the test are:

==10830== LEAK SUMMARY:
==10830==    definitely lost: 251,999 bytes in 7,867 blocks.
==10830==    indirectly lost: 1,600 bytes in 38 blocks.
==10830==      possibly lost: 57,232 bytes in 209 blocks.
==10830==    still reachable: 13,411,291 bytes in 29,753 blocks.
==10830==         suppressed: 0 bytes in 0 blocks.

Still some work left to do, I think. But I'm curious if your results will match mine with this one patch.

Thanks again for you help and assistance.

Regards

Phil
diff --git a/gdb/python/python-utils.c b/gdb/python/python-utils.c
index c6c305f..f9c9486 100644
--- a/gdb/python/python-utils.c
+++ b/gdb/python/python-utils.c
@@ -82,7 +82,11 @@ python_string_to_unicode (PyObject *obj)
   /* If obj is already a unicode string, just return it.
      I wish life was always that simple...  */
   if (PyUnicode_Check (obj))
-    unicode_str = obj;
+    {
+      unicode_str = obj;
+      Py_INCREF (obj);
+    }
+  
   else if (PyString_Check (obj))
     unicode_str = PyUnicode_FromEncodedObject (obj, host_charset (), NULL);
   else
@@ -137,12 +141,15 @@ char *
 python_string_to_target_string (PyObject *obj)
 {
   PyObject *str;
+  char *result;
 
   str = python_string_to_unicode (obj);
   if (str == NULL)
     return NULL;
 
-  return unicode_to_target_string (str);
+  result = unicode_to_target_string (str);
+  Py_DECREF (str);
+  return result;
 }
 
 /* Converts a python string (8-bit or unicode) to a target string in
@@ -153,12 +160,15 @@ char *
 python_string_to_host_string (PyObject *obj)
 {
   PyObject *str;
+  char *result;
 
   str = python_string_to_unicode (obj);
   if (str == NULL)
     return NULL;
 
-  return unicode_to_encoded_string (str, host_charset ());
+  result = unicode_to_encoded_string (str, host_charset ()); 
+  Py_DECREF (str);
+  return result;
 }
 
 /* Converts a target string of LENGTH bytes in the target's charset to a

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]