SVN: ZODB/trunk/src/ Fixed some None ref leaks in cPickleCache.c

Jim Fulton <[email protected]>
Newsgroups gmane.comp.python.zope.zodb.cvs
Message-ID <[email protected]>
Log message for revision 116146:
  Fixed some None ref leaks in cPickleCache.c
  

Changed:
  U   ZODB/trunk/src/ZODB/tests/testCache.py
  U   ZODB/trunk/src/persistent/cPickleCache.c
  U   ZODB/trunk/src/persistent/tests/test_PickleCache.py

-=-
Modified: ZODB/trunk/src/ZODB/tests/testCache.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testCache.py	2010-09-02 15:51:14 UTC (rev 116145)
+++ ZODB/trunk/src/ZODB/tests/testCache.py	2010-09-02 15:57:39 UTC (rev 116146)
@@ -25,6 +25,7 @@
 from ZODB.utils import p64
 import doctest
 import gc
+import sys
 import threading
 import time
 import transaction
@@ -337,6 +338,8 @@
         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 @@
         # 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)

Modified: ZODB/trunk/src/persistent/cPickleCache.c
===================================================================
--- ZODB/trunk/src/persistent/cPickleCache.c	2010-09-02 15:51:14 UTC (rev 116145)
+++ ZODB/trunk/src/persistent/cPickleCache.c	2010-09-02 15:57:39 UTC (rev 116146)
@@ -242,6 +242,8 @@
               Py_DECREF(method);
               if (temp == NULL)
                 error_occurred = 1;
+              else
+                Py_DECREF(temp);
             }
 
           here = placeholder.r_next;
@@ -354,7 +356,6 @@
 {
   static PyObject *_p_invalidate = NULL;
   PyObject *meth, *v;
-  int result;
 
   v = PyDict_GetItem(self->data, key);
   if (v == NULL)
@@ -392,9 +393,10 @@
 
   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 @@
     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;
     }
 

Modified: ZODB/trunk/src/persistent/tests/test_PickleCache.py
===================================================================
--- ZODB/trunk/src/persistent/tests/test_PickleCache.py	2010-09-02 15:51:14 UTC (rev 116145)
+++ ZODB/trunk/src/persistent/tests/test_PickleCache.py	2010-09-02 15:57:39 UTC (rev 116146)
@@ -109,7 +109,7 @@
 
     """
 
-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 @@
     >>> sys.getrefcount(None) - old
     0
 
+    >>> _ = conn.root.p.keys()
+    >>> old = sys.getrefcount(None)
+    >>> conn._cache.minimize()
+    >>> sys.getrefcount(None) - old
+    0
+
     >>> db.close()
 
     """
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.