Commits

Kirill Simonov  committed 6dde7da Draft

Fix a leak in _syckmodule.c (thanks, jbj)

Change the production status to Stable.

  • Participants
  • Parent commits 5907580

Comments (0)

Files changed (3)

File ext/_syckmodule.c

     if (PyList_Append(self->symbols, (PyObject *)object) < 0)
         goto error;
 
+    Py_DECREF(object);
+
     index = PyList_GET_SIZE(self->symbols);
     PyGILState_Release(gs);
     return index;
     }
 
     value = PyList_GetItem(self->symbols, index);
+    Py_XINCREF(value);
 
     Py_DECREF(self->symbols);
     self->symbols = NULL;
 URL = "http://pyyaml.org/wiki/PySyck"
 DOWNLOAD_URL = "http://pyyaml.org/download/pysyck/%s-%s.tar.gz" % (NAME, VERSION)
 CLASSIFIERS = [
-    "Development Status :: 3 - Alpha",
+    "Development Status :: 5 - Production/Stable",
     "Intended Audience :: Developers",
     "License :: OSI Approved :: BSD License",
     "Programming Language :: Python",

File tests/test_parser.py

 
 import _syck
 
-import StringIO, gc
+import StringIO, gc, sys
 
 EXAMPLE = """
 -
 - *alias
 """
 
+LEAKS = """
+- mere scalar
+- [ sequence, may, leak, too]
+- {"it's": mapping, with: many, potential: leaks}
+- {sequence: [], mapping: {}}
+"""
+
 class TestAttributes(unittest.TestCase):
 
     def testAttributes(self):
         node = parser.parse()
         self.assert_(node.value[0] is node.value[1])
 
+class TestLeaks(unittest.TestCase):
+
+    def testLeaks(self):
+        parser = _syck.Parser(LEAKS)
+        node = parser.parse()
+        dummy = []
+        self.checkLeaks(node, dummy)
+
+    def checkLeaks(self, node, dummy):
+        self.assertEqual(sys.getrefcount(node), sys.getrefcount(dummy))
+        self.assertEqual(sys.getrefcount(node.value), 2)
+        dummy = []
+        container = [dummy]
+        if isinstance(node, _syck.Seq):
+            for item in node.value:
+                self.checkLeaks(item, dummy)
+        elif isinstance(node, _syck.Map):
+            for key in node.value:
+                self.checkLeaks(key, dummy)
+                value = node.value[key]
+                self.checkLeaks(value, dummy)
+