]> 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:44:31 +0000 (19:44 +0000)
committerThomas Heller <theller@ctypes.org>
Thu, 22 Mar 2007 19:44:31 +0000 (19:44 +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 0d9ec6c238c32e65bfc3bf3d2462d19243ae3a03..064e01d6cf4190d40649019f534aa8564ace390e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -361,8 +361,6 @@ Library
 
 - Bug #1643943: Fix time.strptime's support for the %U directive.
 
-- Patch #1643874: memory leak in ctypes fixed.
-
 - Patch #1507247: tarfile.py: use current umask for intermediate
   directories.
 
index 1a6ceaf6cf15c61d9d57a76ff5631273abf99485..9b9088259bf0f9b2845d97695e6879fd6d88cef1 100644 (file)
@@ -1461,19 +1461,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) {
@@ -1501,19 +1492,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);
 }