[Zope-Checkins] CVS: Zope3/lib/python/Persistence/BTrees - BucketTemplate.c:1.9

Tim Peters tim.one@comcast.net
Tue, 18 Jun 2002 11:53:43 -0400


Update of /cvs-repository/Zope3/lib/python/Persistence/BTrees
In directory cvs.zope.org:/tmp/cvs-serv25818

Modified Files:
	BucketTemplate.c 
Log Message:
bucket_split():  Don't leak the keys if memory for values can't be found.


=== Zope3/lib/python/Persistence/BTrees/BucketTemplate.c 1.8 => 1.9 ===
 
     if (index < 0 || index >= self->len)
-	index = self->len/2;
+	index = self->len / 2;
 
-    next_size = self->len-index;
+    next_size = self->len - index;
 
     next->keys = BTree_Malloc(sizeof(KEY_TYPE) * next_size);
     if (!next->keys)
@@ -439,15 +439,17 @@
     memcpy(next->keys, self->keys + index, sizeof(KEY_TYPE) * next_size);
     if (self->values) {
 	next->values = BTree_Malloc(sizeof(VALUE_TYPE) * next_size);
-	if (!next->values)
-	    /* XXX does this leak the keys? */
-	    return -1;
-	memcpy(next->values, self->values+index,
+	if (!next->values) {
+            free(next->keys);
+            next->keys = NULL;
+            return -1;
+        }
+	memcpy(next->values, self->values + index,
 	       sizeof(VALUE_TYPE) * next_size);
     }
     next->size = next_size;
     next->len = next_size;
-    self->len =index;
+    self->len = index;
 
     next->next = self->next;