Commit 0b3504cd authored by Tim Peters's avatar Tim Peters

Bucket_grow(): This could leak memory in error cases; repaired.

parent 9e57fe53
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define BUCKETTEMPLATE_C "$Id: BucketTemplate.c,v 1.41 2002/06/13 19:19:41 tim_one Exp $\n" #define BUCKETTEMPLATE_C "$Id: BucketTemplate.c,v 1.42 2002/06/17 19:03:55 tim_one Exp $\n"
/* Use BUCKET_SEARCH to find the index at which a key belongs. /* Use BUCKET_SEARCH to find the index at which a key belongs.
* INDEX An int lvalue to hold the index i such that KEY belongs at * INDEX An int lvalue to hold the index i such that KEY belongs at
...@@ -140,9 +140,12 @@ Bucket_grow(Bucket *self, int newsize, int noval) ...@@ -140,9 +140,12 @@ Bucket_grow(Bucket *self, int newsize, int noval)
UNLESS (noval) UNLESS (noval)
{ {
UNLESS (values = PyRealloc(self->values, values = PyRealloc(self->values, sizeof(VALUE_TYPE) * newsize);
sizeof(VALUE_TYPE) * newsize)) if (values == NULL)
{
free(keys);
return -1; return -1;
}
self->values = values; self->values = values;
} }
self->keys = keys; self->keys = keys;
...@@ -155,10 +158,15 @@ Bucket_grow(Bucket *self, int newsize, int noval) ...@@ -155,10 +158,15 @@ Bucket_grow(Bucket *self, int newsize, int noval)
return -1; return -1;
UNLESS (noval) UNLESS (noval)
{ {
UNLESS (self->values = PyMalloc(sizeof(VALUE_TYPE) * newsize)) self->values = PyMalloc(sizeof(VALUE_TYPE) * newsize);
if (self->values == NULL)
{
free(self->keys);
self->keys = NULL;
return -1; return -1;
} }
} }
}
self->size = newsize; self->size = newsize;
return 0; return 0;
......
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