end18 / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

Memory leak affecting Process.getcwd() on Windows #62

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run test/test_memory_leaks.py script
2. test_getcwd fails signaling a memory leak in the C implementation (file 
psutil/_psutil_mswindows.c function get_process_cwd())

Original issue reported on code.google.com by billiej...@gmail.com on 3 Sep 2009 at 7:53

GoogleCodeExporter commented 9 years ago
I would bet that the problem is this code: 

    returnPyObj = Py_BuildValue("N", PyUnicode_AsUTF8String(
                      PyUnicode_FromWideChar(currentDirectoryContent,
                          currentDirectory.Length / 2)
                      )
                  );

It's creating a Python object and then since we're not keeping the handle to the
object, we can't decrement the reference count, and we end up with a leaked 
object. 
For an example of what I did in the get_arg_list() code:

        for( i=0; i<nArgs; i++) {
            arg_from_wchar = PyUnicode_FromWideChar(szArglist[i],
                                 wcslen(szArglist[i])
                              );

            arg = PyUnicode_AsUTF8String(arg_from_wchar);
            Py_XDECREF(arg_from_wchar);
            PyList_Append(argList, arg);
            Py_XDECREF(arg);
        }
    }

We probably need to create explicit Python objects so we can store and then 
decrement
the reference when we're done with it.

Original comment by jlo...@gmail.com on 4 Sep 2009 at 3:52

GoogleCodeExporter commented 9 years ago
Fixed in r428

Original comment by jlo...@gmail.com on 4 Sep 2009 at 4:33

GoogleCodeExporter commented 9 years ago

Original comment by billiej...@gmail.com on 17 Sep 2009 at 8:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Updated csets after the SVN -> Mercurial migration:
r428 == revision d22ed65c83a6

Original comment by g.rodola on 2 Mar 2013 at 11:50