[Zope3-checkins] CVS: Zope3/src/zodb/btrees - BTreeTemplate.c:1.14

Tim Peters tim.one@comcast.net
Fri, 11 Apr 2003 11:55:32 -0400


Update of /cvs-repository/Zope3/src/zodb/btrees
In directory cvs.zope.org:/tmp/cvs-serv17860/src/zodb/btrees

Modified Files:
	BTreeTemplate.c 
Log Message:
_BTree_set():  We leaked a reference to the first key of the second
bucket when deleting the first child of a BTree node with more than one
child.  This caused >600 int objects to leak in the OI and OO flavors
of testRemoveSucceeds.


=== Zope3/src/zodb/btrees/BTreeTemplate.c 1.13 => 1.14 ===
--- Zope3/src/zodb/btrees/BTreeTemplate.c:1.13	Thu Apr 10 19:40:27 2003
+++ Zope3/src/zodb/btrees/BTreeTemplate.c	Fri Apr 11 11:55:32 2003
@@ -767,9 +767,22 @@
 
     /* Remove the child from self->data. */
     Py_DECREF(d->child);
+#ifdef KEY_TYPE_IS_PYOBJECT
     if (min) {
         DECREF_KEY(d->key);
     }
+    else if (self->len > 1) {
+	/* We're deleting the first child of a BTree with more than one
+	 * child.  The key at d+1 is about to be shifted into slot 0,
+	 * and hence never to be referenced again (the key in slot 0 is
+	 * trash).
+	 */
+	DECREF_KEY((d+1)->key);
+    }
+    /* Else min==0 and len==1:  we're emptying the BTree entirely, and
+     * there is no key in need of decrefing.
+     */
+#endif
     --self->len;
     if (min < self->len)
         memmove(d, d+1, (self->len - min) * sizeof(BTreeItem));