diff options
author | Thomas Heller <theller@ctypes.org> | 2007-03-22 19:44:31 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2007-03-22 19:44:31 (GMT) |
commit | f493cbd8248650e14422ea04e1c3953fdcacd218 (patch) | |
tree | 159cd33abb56367817cc11340b6d0e4c8c666877 /Modules | |
parent | bfcc9755277588dc0cb75f1c965f5c1f3c256ed4 (diff) | |
download | cpython-f493cbd8248650e14422ea04e1c3953fdcacd218.zip cpython-f493cbd8248650e14422ea04e1c3953fdcacd218.tar.gz cpython-f493cbd8248650e14422ea04e1c3953fdcacd218.tar.bz2 |
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.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/cfield.c | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 1a6ceaf..9b90882 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -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); } |