[Python-checkins] r46651 - in python/trunk: Lib/subprocess.py PC/_subprocess.c

georg.brandl python-checkins at python.org
Mon Jun 5 00:15:43 CEST 2006


Author: georg.brandl
Date: Mon Jun  5 00:15:37 2006
New Revision: 46651

Modified:
   python/trunk/Lib/subprocess.py
   python/trunk/PC/_subprocess.c
Log:
Bug #1500293: fix memory leaks in _subprocess module.


Modified: python/trunk/Lib/subprocess.py
==============================================================================
--- python/trunk/Lib/subprocess.py	(original)
+++ python/trunk/Lib/subprocess.py	Mon Jun  5 00:15:37 2006
@@ -388,6 +388,7 @@
             hStdInput = None
             hStdOutput = None
             hStdError = None
+            wShowWindow = 0
         class pywintypes:
             error = IOError
 else:
@@ -744,18 +745,17 @@
                 args = list2cmdline(args)
 
             # Process startup details
-            default_startupinfo = STARTUPINFO()
             if startupinfo is 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

Modified: python/trunk/PC/_subprocess.c
==============================================================================
--- python/trunk/PC/_subprocess.c	(original)
+++ python/trunk/PC/_subprocess.c	Mon Jun  5 00:15:37 2006
@@ -250,19 +250,23 @@
 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) {
@@ -270,8 +274,11 @@
 		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*


More information about the Python-checkins mailing list