]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Bug #1500293: fix memory leaks in _subprocess module.
authorGeorg Brandl <georg@python.org>
Sun, 4 Jun 2006 22:15:45 +0000 (22:15 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 4 Jun 2006 22:15:45 +0000 (22:15 +0000)
 (backport from rev. 46651)

Lib/subprocess.py
PC/_subprocess.c

index bbd26c7b0e80798f1bf4e92b6150bd30c44f3143..2750f79663b7328d2df0b95c0609e91fd58ccdd3 100644 (file)
@@ -369,6 +369,7 @@ if mswindows:
             hStdInput = None
             hStdOutput = None
             hStdError = None
+            wShowWindow = 0
         class pywintypes:
             error = IOError
 else:
@@ -662,18 +663,17 @@ class Popen(object):
                 args = list2cmdline(args)
 
             # Process startup details
-            default_startupinfo = STARTUPINFO()
             if startupinfo == None:
-                startupinfo = default_startupinfo
-            if not None in (p2cread, c2pwrite, errwrite):
+                startupinfo = STARTUPINFO()
+            if None not in (p2cread, c2pwrite, errwrite):
                 startupinfo.dwFlags |= STARTF_USESTDHANDLES
                 startupinfo.hStdInput = p2cread
                 startupinfo.hStdOutput = c2pwrite
                 startupinfo.hStdError = errwrite
 
             if shell:
-                default_startupinfo.dwFlags |= STARTF_USESHOWWINDOW
-                default_startupinfo.wShowWindow = SW_HIDE
+                startupinfo.dwFlags |= STARTF_USESHOWWINDOW
+                startupinfo.wShowWindow = SW_HIDE
                 comspec = os.environ.get("COMSPEC", "cmd.exe")
                 args = comspec + " /c " + args
                 if (GetVersion() >= 0x80000000L or
index 61544c32343ac25041d60eff58665c4885a644c9..ddaef5ca341388486cf27fc15c6cdcb7fb7308da 100644 (file)
@@ -247,19 +247,23 @@ static int
 getint(PyObject* obj, char* name)
 {
        PyObject* value;
+       int ret;
 
        value = PyObject_GetAttrString(obj, name);
        if (! value) {
                PyErr_Clear(); /* FIXME: propagate error? */
                return 0;
        }
-       return (int) PyInt_AsLong(value);
+       ret = (int) PyInt_AsLong(value);
+       Py_DECREF(value);
+       return ret;
 }
 
 static HANDLE
 gethandle(PyObject* obj, char* name)
 {
        sp_handle_object* value;
+       HANDLE ret;
 
        value = (sp_handle_object*) PyObject_GetAttrString(obj, name);
        if (! value) {
@@ -267,8 +271,11 @@ gethandle(PyObject* obj, char* name)
                return NULL;
        }
        if (value->ob_type != &sp_handle_type)
-               return NULL;
-       return value->handle;
+               ret = NULL;
+       else
+               ret = value->handle;
+       Py_DECREF(value);
+       return ret;
 }
 
 static PyObject*