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
from ZODB.utils import p64
import doctest
import gc
import sys
import threading
import time
import transaction
......@@ -337,6 +338,8 @@ class CacheErrors(unittest.TestCase):
def add(key, obj):
self.cache[key] = obj
nones = sys.getrefcount(None)
key = p64(2)
# value isn't persistent
self.assertRaises(TypeError, add, key, 12)
......@@ -360,6 +363,8 @@ class CacheErrors(unittest.TestCase):
# same object, different keys
self.assertRaises(ValueError, add, p64(0), o)
self.assertEqual(sys.getrefcount(None), nones)
def checkTwoCaches(self):
jar2 = StubDataManager()
cache2 = PickleCache(jar2)
......
......@@ -242,6 +242,8 @@ scan_gc_items(ccobject *self, int target, PY_LONG_LONG target_bytes)
Py_DECREF(method);
if (temp == NULL)
error_occurred = 1;
else
Py_DECREF(temp);
}
here = placeholder.r_next;
......@@ -354,7 +356,6 @@ _invalidate(ccobject *self, PyObject *key)
{
static PyObject *_p_invalidate = NULL;
PyObject *meth, *v;
int result;
v = PyDict_GetItem(self->data, key);
if (v == NULL)
......@@ -392,9 +393,10 @@ _invalidate(ccobject *self, PyObject *key)
v = PyObject_CallObject(meth, NULL);
Py_DECREF(meth);
result = v == NULL ? -1 : 0;
if (v == NULL)
return -1;
Py_DECREF(v);
return result;
return 0;
}
static PyObject *
......@@ -1039,9 +1041,11 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v)
return -1;
if (! PyString_Check(oid))
{
Py_DECREF(oid);
PyErr_Format(PyExc_TypeError,
"Cached object oid must be a string, not a %s",
oid->ob_type->tp_name);
return -1;
}
......
......@@ -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
>>> import transaction
......@@ -127,6 +127,12 @@ def cache_invalidate_used_to_leak_None_ref():
>>> sys.getrefcount(None) - old
0
>>> _ = conn.root.p.keys()
>>> old = sys.getrefcount(None)
>>> conn._cache.minimize()
>>> sys.getrefcount(None) - old
0
>>> 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