Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
giampaolo opened this issue May 23, 2014 · 4 comments
Closed

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

giampaolo opened this issue May 23, 2014 · 4 comments

Comments

@giampaolo
Copy link
Owner

From billiej...@gmail.com on September 03, 2009 21:53:56

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: http://code.google.com/p/psutil/issues/detail?id=62

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on September 03, 2009 20:52:20

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.

Status: Accepted

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on September 03, 2009 21:33:55

Fixed in r428

Status: FixedInSVN

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on September 17, 2009 01:57:42

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on March 02, 2013 03:50:25

Updated csets after the SVN -> Mercurial migration: r428 == revision d22ed65c83a6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant