[Zodb-checkins] CVS: Zope/lib/python/BTrees - MergeTemplate.c:1.13 SetOpTemplate.c:1.18

Tim Peters tim.one@comcast.net
Mon, 3 Jun 2002 13:21:56 -0400


Update of /cvs-repository/Zope/lib/python/BTrees
In directory cvs.zope.org:/tmp/cvs-serv19248

Modified Files:
	MergeTemplate.c SetOpTemplate.c 
Log Message:
Repaired various leaks due to code leaving references behind in
SetIteration structs.


=== Zope/lib/python/BTrees/MergeTemplate.c 1.12 => 1.13 ===
   int cmp12, cmp13, cmp23, mapping=0, set;
 
-  /* XXX Looks like the various "return NULL;" exits from here on can
-   * XXX leak references saved away in i1.set, i2.set, i3.set.
-   */
-  if (initSetIteration(&i1, OBJECT(s1), 0, &mapping) < 0) return NULL;
-  if (initSetIteration(&i2, OBJECT(s2), 0, &mapping) < 0) return NULL;
-  if (initSetIteration(&i3, OBJECT(s3), 0, &mapping) < 0) return NULL;
+  if (initSetIteration(&i1, OBJECT(s1), 0, &mapping) < 0) goto err;
+  if (initSetIteration(&i2, OBJECT(s2), 0, &mapping) < 0) goto err;
+  if (initSetIteration(&i3, OBJECT(s3), 0, &mapping) < 0) goto err;
 
   set = ! mapping;
 
@@ -80,9 +77,9 @@
         goto err;
     }
 
-  if (i1.next(&i1) < 0) return NULL;
-  if (i2.next(&i2) < 0) return NULL;
-  if (i3.next(&i3) < 0) return NULL;
+  if (i1.next(&i1) < 0) goto err;
+  if (i2.next(&i2) < 0) goto err;
+  if (i3.next(&i3) < 0) goto err;
 
   while (i1.position >= 0 && i2.position >= 0 && i3.position >= 0)
     {


=== Zope/lib/python/BTrees/SetOpTemplate.c 1.17 => 1.18 ===
   int cmp, merge=0;
 
-  if (initSetIteration(&i1, s1, w1, &merge) < 0) return NULL;
-  if (initSetIteration(&i2, s2, w2, &merge) < 0) return NULL;
+  if (initSetIteration(&i1, s1, w1, &merge) < 0) goto err;
+  if (initSetIteration(&i2, s2, w2, &merge) < 0) goto err;
 
   if (merge)
     {
@@ -247,12 +247,12 @@
         goto err;
     }
 
-  if (i1.next(&i1) < 0) return NULL;
-  if (i2.next(&i2) < 0) return NULL;
+  if (i1.next(&i1) < 0) goto err;
+  if (i2.next(&i2) < 0) goto err;
 
   while (i1.position >= 0 && i2.position >= 0)
     {
-      TEST_KEY_SET_OR(cmp, i1.key, i2.key) return NULL;
+      TEST_KEY_SET_OR(cmp, i1.key, i2.key) goto err;
       if(cmp < 0)
 	{
 	  if(c1)
@@ -489,20 +489,17 @@
             /* No cheap way:  iterate over set's elements one at a time. */
             int merge;  /* dummy needed for initSetIteration */
 
-            if (initSetIteration(&setiter, set, 1, &merge) < 0)
-                goto Error;
-            if (setiter.next(&setiter) < 0)
-                goto Error;
+            if (initSetIteration(&setiter, set, 1, &merge) < 0) goto Error;
+            if (setiter.next(&setiter) < 0) goto Error;
             while (setiter.position >= 0) {
                 if (result->len >= result->size && Bucket_grow(result, -1, 1) < 0)
                     goto Error;
                 COPY_KEY(result->keys[result->len], setiter.key);
                 ++result->len;
                 /* We know the key is an int, so no need to incref it. */
-                if (setiter.next(&setiter) < 0)
-                    goto Error;
+                if (setiter.next(&setiter) < 0) goto Error;
             }
-            Py_XDECREF(setiter.set);
+            Py_DECREF(setiter.set);
             setiter.set = NULL;
         }
         Py_DECREF(set);