[Python-checkins] r54533 - in python/trunk: Misc/NEWS Modules/_ctypes/cfield.c
thomas.heller
python-checkins at python.org
Thu Mar 22 20:44:35 CET 2007
Author: thomas.heller
Date: Thu Mar 22 20:44:31 2007
New Revision: 54533
Modified:
python/trunk/Misc/NEWS
python/trunk/Modules/_ctypes/cfield.c
Log:
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.
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Thu Mar 22 20:44:31 2007
@@ -361,8 +361,6 @@
- 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.
Modified: python/trunk/Modules/_ctypes/cfield.c
==============================================================================
--- python/trunk/Modules/_ctypes/cfield.c (original)
+++ python/trunk/Modules/_ctypes/cfield.c Thu Mar 22 20:44:31 2007
@@ -1461,19 +1461,10 @@
#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 @@
} 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);
}
More information about the Python-checkins
mailing list