Commit ff24f9df authored by Jeremy Hylton's avatar Jeremy Hylton

(Possibly) correct use of Python memory APIs.

Fix SF bug #516768 reported by Dave Wallace.

Replace use of PyMem_DEL() with PyObject_Del() on object dealloc
functions.  The use of PyMem_DEL() is incorrect for object
deallocation, because it only ever calls the low-level free().  If a
custom allocator like pymalloc is used, it needs to be called to free
the memory.

Also replace bare malloc() and realloc() with PyMem_Malloc() and
PyMem_Realloc().  I think this isn't a strict bug fix, but a would be
nice.  It guarantees that BTrees objects get their memory from the
same allocator as the Python core.
parent 0afd8bdf
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define BTREEITEMSTEMPLATE_C "$Id: BTreeItemsTemplate.c,v 1.8 2002/02/11 23:40:40 gvanrossum Exp $\n" #define BTREEITEMSTEMPLATE_C "$Id: BTreeItemsTemplate.c,v 1.9 2002/03/08 18:33:01 jeremy Exp $\n"
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD
...@@ -38,7 +38,7 @@ BTreeItems_dealloc(BTreeItems *self) ...@@ -38,7 +38,7 @@ BTreeItems_dealloc(BTreeItems *self)
Py_XDECREF(self->firstbucket); Py_XDECREF(self->firstbucket);
Py_XDECREF(self->lastbucket); Py_XDECREF(self->lastbucket);
Py_XDECREF(self->currentbucket); Py_XDECREF(self->currentbucket);
PyMem_DEL(self); PyObject_DEL(self);
} }
static int static int
......
...@@ -211,7 +211,7 @@ PyMalloc(size_t sz) ...@@ -211,7 +211,7 @@ PyMalloc(size_t sz)
ASSERT(sz > 0, "non-positive size malloc", NULL); ASSERT(sz > 0, "non-positive size malloc", NULL);
if ((r=malloc(sz))) return r; if ((r=PyMem_Malloc(sz))) return r;
PyErr_NoMemory(); PyErr_NoMemory();
return NULL; return NULL;
...@@ -224,8 +224,8 @@ PyRealloc(void *p, size_t sz) ...@@ -224,8 +224,8 @@ PyRealloc(void *p, size_t sz)
ASSERT(sz > 0, "non-positive size realloc", NULL); ASSERT(sz > 0, "non-positive size realloc", NULL);
if (p) r=realloc(p,sz); if (p) r=PyMem_Realloc(p,sz);
else r=malloc(sz); else r=PyMem_Malloc(sz);
UNLESS (r) PyErr_NoMemory(); UNLESS (r) PyErr_NoMemory();
...@@ -270,7 +270,7 @@ static char BTree_module_documentation[] = ...@@ -270,7 +270,7 @@ static char BTree_module_documentation[] =
"\n" "\n"
MASTER_ID MASTER_ID
BTREEITEMSTEMPLATE_C BTREEITEMSTEMPLATE_C
"$Id: BTreeModuleTemplate.c,v 1.20 2002/02/21 21:41:17 jeremy Exp $\n" "$Id: BTreeModuleTemplate.c,v 1.21 2002/03/08 18:33:01 jeremy Exp $\n"
BTREETEMPLATE_C BTREETEMPLATE_C
BUCKETTEMPLATE_C BUCKETTEMPLATE_C
KEYMACROS_H KEYMACROS_H
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.24 2002/02/28 20:12:00 jeremy Exp $\n" #define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.25 2002/03/08 18:33:01 jeremy Exp $\n"
/* /*
** _BTree_get ** _BTree_get
...@@ -1242,7 +1242,7 @@ BTree_dealloc(BTree *self) ...@@ -1242,7 +1242,7 @@ BTree_dealloc(BTree *self)
PER_DEL(self); PER_DEL(self);
Py_DECREF(self->ob_type); Py_DECREF(self->ob_type);
PyMem_DEL(self); PyObject_Del(self);
} }
static int static int
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define BUCKETTEMPLATE_C "$Id: BucketTemplate.c,v 1.27 2002/02/21 21:41:17 jeremy Exp $\n" #define BUCKETTEMPLATE_C "$Id: BucketTemplate.c,v 1.28 2002/03/08 18:33:01 jeremy Exp $\n"
/* /*
** _bucket_get ** _bucket_get
...@@ -1137,7 +1137,7 @@ Bucket_dealloc(Bucket *self) ...@@ -1137,7 +1137,7 @@ Bucket_dealloc(Bucket *self)
PER_DEL(self); PER_DEL(self);
Py_DECREF(self->ob_type); Py_DECREF(self->ob_type);
PyMem_DEL(self); PyObject_Del(self);
} }
/* Code to access Bucket objects as mappings */ /* Code to access Bucket objects as mappings */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment