[Zodb-checkins] CVS: Zope3/lib/python/Persistence/BTrees - TreeSetTemplate.c:1.1.2.4
Jeremy Hylton
jeremy@zope.com
Thu, 28 Feb 2002 16:45:54 -0500
Update of /cvs-repository/Zope3/lib/python/Persistence/BTrees
In directory cvs.zope.org:/tmp/cvs-serv9720
Modified Files:
Tag: Zope-3x-branch
TreeSetTemplate.c
Log Message:
TreeSet_update() leaked memory.
This was the same bug as Set_update().
XXX The TreeSet_update() and Set_update() methods are identical except
for the function they call to add an item to the set. Should refactor
the code to avoid all the duplication.
=== Zope3/lib/python/Persistence/BTrees/TreeSetTemplate.c 1.1.2.3 => 1.1.2.4 ===
_TreeSet_update(BTree *self, PyObject *seq)
{
- int n = 0;
+ int n = -1;
PyObject *iter, *v;
int ind;
@@ -43,20 +43,27 @@
while (1) {
v = PyIter_Next(iter);
if (v == NULL) {
- if (PyErr_Occurred()) {
- Py_DECREF(iter);
- return -1;
- } else
+ if (PyErr_Occurred())
+ goto err;
+ else
break;
}
ind = _BTree_set(self, v, Py_None, 1, 1);
Py_DECREF(v);
- if (ind < 0) {
- Py_DECREF(iter);
- return -1;
- } else
+ if (ind < 0)
+ goto err;
+ else
n += ind;
}
+ /* n starts out at -1, which is the error return value. If
+ this point is reached, then there is no error. n must be
+ incremented to account for the initial value of -1 instead of
+ 0.
+ */
+ n++;
+
+ err:
+ Py_DECREF(iter);
return n;
}