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 in the windows version of get_ppid_map #448

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

Memory leak in the windows version of get_ppid_map #448

giampaolo opened this issue May 23, 2014 · 2 comments

Comments

@giampaolo
Copy link
Owner

From [email protected] on November 30, 2013 00:08:36

What steps will reproduce the problem?  
The following script will consume an increasing amount of memory:

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import logging
import psutil
import time

while True:
    try:
        for pid in psutil.get_pid_list():
            m = psutil.Process(pid)
        psutil._psmswindows.get_ppid_map()
    except Exception as ex:
        logging.warning(ex)
    finally:
        time.sleep(0.01) 

What is the expected output?  
No memory leaks 

What do you see instead?  
A memory leak 

What version of psutil are you using? What Python version?  
hg clone from  Tue Nov 26 18:00:55 2013 +0100
changeset:   1690:578f037d6dbb 

On what operating system? Is it 32bit or 64bit version?  
Windows 7 32 bit 

Please provide any additional information below.  
The following changeset resolves the problem for me

changeset:   1691:4862f1b232e9
tag:         tip
user:        Ulrich Klank <[email protected]>
date:        Sat Nov 30 00:01:59 2013 +0100
summary:     Fix for memory leak in windows version of get_ppid_map

diff -r 578f037d6dbb -r 4862f1b232e9 psutil/_psutil_mswindows.c
--- a/psutil/_psutil_mswindows.c        Tue Nov 26 18:00:55 2013 +0100
+++ b/psutil/_psutil_mswindows.c        Sat Nov 30 00:01:59 2013 +0100
@@ -2868,14 +2868,22 @@

     if (Process32First(handle, &pe)) {
         do {
+
             pid = Py_BuildValue("I", pe.th32ProcessID);
             if (pid == NULL)
                 goto error;
+
             ppid = Py_BuildValue("I", pe.th32ParentProcessID);
             if (ppid == NULL)
                 goto error;
+
             if (PyDict_SetItem(py_retdict, pid, ppid))
                 goto error;
+
+            Py_XDECREF(pid);
+            Py_XDECREF(ppid);
+            pid = NULL;
+            ppid = NULL;
         } while (Process32Next(handle, &pe));
     }

Original issue: http://code.google.com/p/psutil/issues/detail?id=448

@giampaolo
Copy link
Owner Author

From g.rodola on December 02, 2013 11:16:48

Thanks. Fixed in revision 385524f5c752 .

Status: FixedInHG
Labels: OpSys-Windows Milestone-1.2.2

@giampaolo
Copy link
Owner Author

From g.rodola on March 10, 2014 04:36:50

Closing out as fixed as 2.0.0 version is finally out.

Status: Fixed
Labels: -Milestone-1.2.2 Milestone-2.0.0

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