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.
This commit is contained in:
Thomas Heller 2007-03-22 19:44:31 +00:00
parent bfcc975527
commit f493cbd824
2 changed files with 8 additions and 23 deletions

View File

@ -361,8 +361,6 @@ Library
- Bug #1643943: Fix time.strptime's support for the %U directive. - 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 - Patch #1507247: tarfile.py: use current umask for intermediate
directories. directories.

View File

@ -1461,19 +1461,10 @@ Z_get(void *ptr, unsigned size)
#endif #endif
#ifdef MS_WIN32 #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 * static PyObject *
BSTR_set(void *ptr, PyObject *value, unsigned size) BSTR_set(void *ptr, PyObject *value, unsigned size)
{ {
BSTR bstr; BSTR bstr;
PyObject *result;
/* convert value into a PyUnicodeObject or NULL */ /* convert value into a PyUnicodeObject or NULL */
if (Py_None == value) { if (Py_None == value) {
@ -1501,19 +1492,15 @@ BSTR_set(void *ptr, PyObject *value, unsigned size)
} else } else
bstr = NULL; bstr = NULL;
if (bstr) { /* free the previous contents, if any */
result = PyCObject_FromVoidPtr((void *)bstr, _my_SysFreeString); if (*(BSTR *)ptr)
if (result == NULL) { SysFreeString(*(BSTR *)ptr);
SysFreeString(bstr);
return NULL; /* and store it */
}
} else {
result = Py_None;
Py_INCREF(result);
}
*(BSTR *)ptr = bstr; *(BSTR *)ptr = bstr;
return result;
/* We don't need to keep any other object */
_RET(value);
} }