[Zodb-checkins] CVS: Zope/lib/python/BTrees - BTreeTemplate.c:1.74

Tim Peters tim.one@comcast.net
Fri, 11 Apr 2003 12:09:59 -0400


Update of /cvs-repository/Zope/lib/python/BTrees
In directory cvs.zope.org:/tmp/cvs-serv20282/lib/python/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.


=== Zope/lib/python/BTrees/BTreeTemplate.c 1.73 => 1.74 ===
--- Zope/lib/python/BTrees/BTreeTemplate.c:1.73	Thu Apr 10 19:36:55 2003
+++ Zope/lib/python/BTrees/BTreeTemplate.c	Fri Apr 11 12:09:58 2003
@@ -757,9 +757,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));