Browse Source

[1028] fixed reference leak to DataSourceClient after get_updater.

JINMEI Tatuya 13 years ago
parent
commit
65bd895a45

+ 18 - 0
src/lib/python/isc/datasrc/tests/datasrc_test.py

@@ -20,6 +20,7 @@ import isc.dns
 import unittest
 import unittest
 import os
 import os
 import shutil
 import shutil
+import sys
 import json
 import json
 
 
 TESTDATA_PATH = os.environ['TESTDATA_PATH'] + os.sep
 TESTDATA_PATH = os.environ['TESTDATA_PATH'] + os.sep
@@ -494,6 +495,23 @@ class DataSrcUpdater(unittest.TestCase):
                          dsc.get_updater(isc.dns.Name("notexistent.example"),
                          dsc.get_updater(isc.dns.Name("notexistent.example"),
                                          True))
                                          True))
 
 
+    def test_client_reference(self):
+        # Temporarily create various objects using factory methods of the
+        # client.  The created objects won't be stored anywhere and
+        # immediately released.  The creation shouldn't affect the reference
+        # to the base client.
+        dsc = isc.datasrc.DataSourceClient("sqlite3", WRITE_ZONE_DB_CONFIG)
+        orig_ref = sys.getrefcount(dsc)
+
+        dsc.find_zone(isc.dns.Name("example.com"))
+        self.assertEqual(orig_ref, sys.getrefcount(dsc))
+
+        dsc.get_iterator(isc.dns.Name("example.com."))
+        self.assertEqual(orig_ref, sys.getrefcount(dsc))
+
+        dsc.get_updater(isc.dns.Name("example.com"), True)
+        self.assertEqual(orig_ref, sys.getrefcount(dsc))
+
 if __name__ == "__main__":
 if __name__ == "__main__":
     isc.log.init("bind10")
     isc.log.init("bind10")
     unittest.main()
     unittest.main()

+ 1 - 0
src/lib/python/isc/datasrc/updater_python.cc

@@ -274,6 +274,7 @@ createZoneUpdaterObject(isc::datasrc::ZoneUpdaterPtr source,
         zoneupdater_type.tp_alloc(&zoneupdater_type, 0));
         zoneupdater_type.tp_alloc(&zoneupdater_type, 0));
     if (py_zi != NULL) {
     if (py_zi != NULL) {
         py_zi->cppobj = source;
         py_zi->cppobj = source;
+        py_zi->base_obj = base_obj;
     }
     }
     if (base_obj != NULL) {
     if (base_obj != NULL) {
         Py_INCREF(base_obj);
         Py_INCREF(base_obj);