summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2007-03-22 19:43:37 (GMT)
committerThomas Heller <theller@ctypes.org>2007-03-22 19:43:37 (GMT)
commit02b8feea9f6974de89fcd1888ef5326d436a7d0a (patch)
treea59682c79a17509fa6db9e1b5890e012c1e93002
parent4d891193d106b147c816dc617f087498df76972a (diff)
downloadcpython-02b8feea9f6974de89fcd1888ef5326d436a7d0a.zip
cpython-02b8feea9f6974de89fcd1888ef5326d436a7d0a.tar.gz
cpython-02b8feea9f6974de89fcd1888ef5326d436a7d0a.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.
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/_ctypes/cfield.c29
2 files changed, 8 insertions, 23 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index e526ac3..ac53f85 100644
--- 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.
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
index 31c3b99..c16a387 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -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);
}