Commits

Thomas Heller  committed 1757f80

Back out "Patch #1643874: memory leak in ctypes fixed."

The code in this patch leaves no way to give up the ownership of a
BSTR instance.

  • Participants
  • Parent commits 52e2fcd
  • Branches 2.5

Comments (0)

Files changed (2)

 
 - Bug #1643943: Fix %U handling for time.strptime.
 
-- Patch #1643874: memory leak in ctypes fixed.
-
 - Bug #1598181: Avoid O(N**2) bottleneck in subprocess communicate(). 
 
 - Patch #1627441: close sockets properly in urllib2.

File Modules/_ctypes/cfield.c

 #endif
 
 #ifdef MS_WIN32
-/* We cannot use SysFreeString as the PyCObject_FromVoidPtr
-   because of different calling convention
-*/
-static void _my_SysFreeString(void *p)
-{
-	SysFreeString((BSTR)p);
-}
-
 static PyObject *
 BSTR_set(void *ptr, PyObject *value, unsigned size)
 {
 	BSTR bstr;
-	PyObject *result;
 
 	/* convert value into a PyUnicodeObject or NULL */
 	if (Py_None == value) {
 	} else
 		bstr = NULL;
 
-	if (bstr) {
-		result = PyCObject_FromVoidPtr((void *)bstr, _my_SysFreeString);
-		if (result == NULL) {
-			SysFreeString(bstr);
-			return NULL;
-		}
-	} else {
-		result = Py_None;
-		Py_INCREF(result);
-	}
+	/* free the previous contents, if any */
+	if (*(BSTR *)ptr)
+		SysFreeString(*(BSTR *)ptr);
+	
+	/* and store it */
+	*(BSTR *)ptr = bstr;
 
-	*(BSTR *)ptr = bstr;
-	return result;
+	/* We don't need to keep any other object */
+	_RET(value);
 }