summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-12-08 10:07:46 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-12-08 10:07:46 (GMT)
commitdfe6ad7cc551c55ec6ba0b3808e752e90861714a (patch)
tree4b6c1e42b51563ca37661ea87bbb7b6cf8e4a376 /Modules
parent448e81b2da41e2ad89302cc8cb384795f9f6306c (diff)
parent12f33df4a2712c23beba00bcf60338dd980be2d7 (diff)
downloadcpython-dfe6ad7cc551c55ec6ba0b3808e752e90861714a.zip
cpython-dfe6ad7cc551c55ec6ba0b3808e752e90861714a.tar.gz
cpython-dfe6ad7cc551c55ec6ba0b3808e752e90861714a.tar.bz2
Issue #16628: Fix a memory leak in ctypes.resize().
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/_ctypes.c2
-rw-r--r--Modules/_ctypes/callproc.c2
-rw-r--r--Modules/_ctypes/ctypes.h1
3 files changed, 3 insertions, 2 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 7516306..440e09c 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -2446,7 +2446,7 @@ PyCData_clear(CDataObject *self)
assert(dict); /* Cannot be NULL for CDataObject instances */
Py_CLEAR(self->b_objects);
if ((self->b_needsfree)
- && ((size_t)dict->size > sizeof(self->b_value)))
+ && _CDataObject_HasExternalBuffer(self))
PyMem_Free(self->b_ptr);
self->b_ptr = NULL;
Py_CLEAR(self->b_base);
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index dd441f5..09320cf 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -1658,7 +1658,7 @@ resize(PyObject *self, PyObject *args)
obj->b_size = size;
goto done;
}
- if (obj->b_size <= sizeof(obj->b_value)) {
+ if (!_CDataObject_HasExternalBuffer(obj)) {
/* We are currently using the objects default buffer, but it
isn't large enough any more. */
void *ptr = PyMem_Malloc(size);
diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h
index 27abe65..5237ac2 100644
--- a/Modules/_ctypes/ctypes.h
+++ b/Modules/_ctypes/ctypes.h
@@ -116,6 +116,7 @@ extern int PyObject_stginfo(PyObject *self, Py_ssize_t *psize, Py_ssize_t *palig
extern PyTypeObject PyCData_Type;
#define CDataObject_CheckExact(v) ((v)->ob_type == &PyCData_Type)
#define CDataObject_Check(v) PyObject_TypeCheck(v, &PyCData_Type)
+#define _CDataObject_HasExternalBuffer(v) ((v)->b_ptr != (char *)&(v)->b_value)
extern PyTypeObject PyCSimpleType_Type;
#define PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyCSimpleType_Type)