Commit 64916308 authored by Jim Fulton's avatar Jim Fulton

Fixed some None ref leaks in cPickleCache.c

parent f6bec97e
...@@ -25,6 +25,7 @@ from ZODB.tests.MinPO import MinPO ...@@ -25,6 +25,7 @@ from ZODB.tests.MinPO import MinPO
from ZODB.utils import p64 from ZODB.utils import p64
import doctest import doctest
import gc import gc
import sys
import threading import threading
import time import time
import transaction import transaction
...@@ -337,6 +338,8 @@ class CacheErrors(unittest.TestCase): ...@@ -337,6 +338,8 @@ class CacheErrors(unittest.TestCase):
def add(key, obj): def add(key, obj):
self.cache[key] = obj self.cache[key] = obj
nones = sys.getrefcount(None)
key = p64(2) key = p64(2)
# value isn't persistent # value isn't persistent
self.assertRaises(TypeError, add, key, 12) self.assertRaises(TypeError, add, key, 12)
...@@ -360,6 +363,8 @@ class CacheErrors(unittest.TestCase): ...@@ -360,6 +363,8 @@ class CacheErrors(unittest.TestCase):
# same object, different keys # same object, different keys
self.assertRaises(ValueError, add, p64(0), o) self.assertRaises(ValueError, add, p64(0), o)
self.assertEqual(sys.getrefcount(None), nones)
def checkTwoCaches(self): def checkTwoCaches(self):
jar2 = StubDataManager() jar2 = StubDataManager()
cache2 = PickleCache(jar2) cache2 = PickleCache(jar2)
......
...@@ -242,6 +242,8 @@ scan_gc_items(ccobject *self, int target, PY_LONG_LONG target_bytes) ...@@ -242,6 +242,8 @@ scan_gc_items(ccobject *self, int target, PY_LONG_LONG target_bytes)
Py_DECREF(method); Py_DECREF(method);
if (temp == NULL) if (temp == NULL)
error_occurred = 1; error_occurred = 1;
else
Py_DECREF(temp);
} }
here = placeholder.r_next; here = placeholder.r_next;
...@@ -354,7 +356,6 @@ _invalidate(ccobject *self, PyObject *key) ...@@ -354,7 +356,6 @@ _invalidate(ccobject *self, PyObject *key)
{ {
static PyObject *_p_invalidate = NULL; static PyObject *_p_invalidate = NULL;
PyObject *meth, *v; PyObject *meth, *v;
int result;
v = PyDict_GetItem(self->data, key); v = PyDict_GetItem(self->data, key);
if (v == NULL) if (v == NULL)
...@@ -392,9 +393,10 @@ _invalidate(ccobject *self, PyObject *key) ...@@ -392,9 +393,10 @@ _invalidate(ccobject *self, PyObject *key)
v = PyObject_CallObject(meth, NULL); v = PyObject_CallObject(meth, NULL);
Py_DECREF(meth); Py_DECREF(meth);
result = v == NULL ? -1 : 0; if (v == NULL)
return -1;
Py_DECREF(v); Py_DECREF(v);
return result; return 0;
} }
static PyObject * static PyObject *
...@@ -1039,9 +1041,11 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v) ...@@ -1039,9 +1041,11 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v)
return -1; return -1;
if (! PyString_Check(oid)) if (! PyString_Check(oid))
{ {
Py_DECREF(oid);
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"Cached object oid must be a string, not a %s", "Cached object oid must be a string, not a %s",
oid->ob_type->tp_name); oid->ob_type->tp_name);
return -1; return -1;
} }
......
...@@ -109,7 +109,7 @@ Peristent meta classes work too: ...@@ -109,7 +109,7 @@ Peristent meta classes work too:
""" """
def cache_invalidate_used_to_leak_None_ref(): def cache_invalidate_and_minimize_used_to_leak_None_ref():
"""Persistent weak references """Persistent weak references
>>> import transaction >>> import transaction
...@@ -127,6 +127,12 @@ def cache_invalidate_used_to_leak_None_ref(): ...@@ -127,6 +127,12 @@ def cache_invalidate_used_to_leak_None_ref():
>>> sys.getrefcount(None) - old >>> sys.getrefcount(None) - old
0 0
>>> _ = conn.root.p.keys()
>>> old = sys.getrefcount(None)
>>> conn._cache.minimize()
>>> sys.getrefcount(None) - old
0
>>> db.close() >>> db.close()
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment