Author: Ronan Lamy <[email protected]>
Branch: cpyext-leakchecking
Changeset: r92001:d4f923fa8dfa
Date: 2017-07-31 16:54 +0100
http://bitbucket.org/pypy/pypy/changeset/d4f923fa8dfa/
Log: fix refleaks in test_tupleobject
diff --git a/pypy/module/cpyext/test/test_tupleobject.py
b/pypy/module/cpyext/test/test_tupleobject.py
--- a/pypy/module/cpyext/test/test_tupleobject.py
+++ b/pypy/module/cpyext/test/test_tupleobject.py
@@ -24,6 +24,7 @@
def test_tuple_realize_refuses_nulls(self, space, api):
py_tuple = api.PyTuple_New(1)
py.test.raises(FatalError, from_ref, space, py_tuple)
+ api.Py_DecRef(py_tuple)
def test_tuple_resize(self, space, api):
w_42 = space.wrap(42)
@@ -70,6 +71,7 @@
w_tuple = from_ref(space, py_tuple)
assert space.eq_w(w_tuple, space.newtuple([space.wrap(42),
space.wrap(43)]))
+ api.Py_DecRef(py_tuple)
def test_getslice(self, space, api):
w_tuple = space.newtuple([space.wrap(i) for i in range(10)])
@@ -174,6 +176,7 @@
res = PyTuple_SetItem(tuple, 0, one);
if (res != 0)
{
+ Py_DECREF(one);
Py_DECREF(tuple);
return NULL;
}
@@ -187,14 +190,13 @@
/* Do something that uses the tuple, but does not incref */
t2 = PyTuple_GetSlice(tuple, 0, 1);
Py_DECREF(t2);
- Py_INCREF(one);
res = PyTuple_SetItem(tuple, 0, one);
- Py_DECREF(tuple);
if (res != 0)
{
- Py_DECREF(one);
+ Py_DECREF(tuple);
return NULL;
}
+ Py_DECREF(tuple);
Py_INCREF(Py_None);
return Py_None;
"""),
@@ -205,4 +207,3 @@
raises(SystemError, module.set_after_use, s)
else:
module.set_after_use(s)
-
diff --git a/pypy/module/cpyext/tupleobject.py
b/pypy/module/cpyext/tupleobject.py
--- a/pypy/module/cpyext/tupleobject.py
+++ b/pypy/module/cpyext/tupleobject.py
@@ -143,6 +143,7 @@
old_ref = tupleobj.c_ob_item[index]
if pyobj_has_w_obj(ref):
# similar but not quite equal to ref.c_ob_refcnt != 1 on CPython
+ decref(space, py_obj)
raise oefmt(space.w_SystemError, "PyTuple_SetItem called on tuple
after"
" use of tuple")
tupleobj.c_ob_item[index] = py_obj # consumes a reference
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit