]> granicus.if.org Git - python/commitdiff
Back out "Patch #1643874: memory leak in ctypes fixed."
authorThomas Heller <theller@ctypes.org>
Thu, 22 Mar 2007 19:43:37 +0000 (19:43 +0000)
committerThomas Heller <theller@ctypes.org>
Thu, 22 Mar 2007 19:43:37 +0000 (19:43 +0000)
The code in this patch leaves no way to give up the ownership of a
BSTR instance.

Misc/NEWS
Modules/_ctypes/cfield.c

index e526ac332d51933e8e4602c559e10af962794f87..ac53f859ab4390427375063b05cb8bf6d374d493 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -287,8 +287,6 @@ Library
 
 - 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.
index 31c3b99fdda9317a1d77acb55331e54a258e78c3..c16a387464f9c928a0dc89daf526a6e2fbbddca0 100644 (file)
@@ -1424,19 +1424,10 @@ Z_get(void *ptr, unsigned size)
 #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) {
@@ -1464,19 +1455,15 @@ BSTR_set(void *ptr, PyObject *value, unsigned size)
        } 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;
-       return result;
+
+       /* We don't need to keep any other object */
+       _RET(value);
 }