1. Armin Rigo
  2. cpython-withatomic

Commits

Florent Xicluna  committed 934239b

Merged revisions 78563 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
r78563 | florent.xicluna | 2010-03-01 21:45:01 +0100 (lun, 01 mar 2010) | 2 lines

#7808: Fix reference leaks in _bsddb and related tests.
........

  • Participants
  • Parent commits 04590ec
  • Branches 2.6

Comments (0)

Files changed (4)

File Lib/bsddb/test/test_compare.py

View file
             errorOut = temp.getvalue()
             if not successRe.search(errorOut):
                 self.fail("unexpected stderr output:\n"+errorOut)
+        sys.exc_traceback = sys.last_traceback = None
 
     def _test_compare_function_exception (self):
         self.startTest ()

File Lib/bsddb/test/test_replication.py

View file
 import os
 import time
 import unittest
+import weakref
 
 from test_all import db, test_support, have_threads, verbose, \
         get_new_environment_path, get_new_database_path
                 | db.DB_INIT_LOG | db.DB_INIT_MPOOL | db.DB_INIT_LOCK |
                 db.DB_INIT_REP | db.DB_RECOVER | db.DB_THREAD, 0666)
 
+        wr = weakref.ref(self)
         self.confirmed_master=self.client_startupdone=False
         def confirmed_master(a,b,c) :
             if b==db.DB_EVENT_REP_MASTER :
+                self = wr()
                 self.confirmed_master=True
 
         def client_startupdone(a,b,c) :
             if b==db.DB_EVENT_REP_STARTUPDONE :
+                self = wr()
                 self.client_startupdone=True
 
         self.dbenvMaster.set_event_notify(confirmed_master)
 class DBBaseReplication(DBReplicationManager):
     def setUp(self) :
         DBReplicationManager.setUp(self)
+        wr = weakref.ref(self)
         def confirmed_master(a,b,c) :
             if (b == db.DB_EVENT_REP_MASTER) or (b == db.DB_EVENT_REP_ELECTED) :
+                self = wr()
                 self.confirmed_master = True
 
         def client_startupdone(a,b,c) :
             if b == db.DB_EVENT_REP_STARTUPDONE :
+                self = wr()
                 self.client_startupdone = True
 
         self.dbenvMaster.set_event_notify(confirmed_master)
         # There are only two nodes, so we don't need to
         # do any routing decision
         def m2c(dbenv, control, rec, lsnp, envid, flags) :
+            self = wr()
             self.m2c.put((control, rec))
 
         def c2m(dbenv, control, rec, lsnp, envid, flags) :
+            self = wr()
             self.c2m.put((control, rec))
 
         self.dbenvMaster.rep_set_transport(13,m2c)
         #self.dbenvClient.set_verbose(db.DB_VERB_FILEOPS_ALL, True)
 
         def thread_master() :
+            self = wr()
             return self.thread_do(self.dbenvMaster, self.c2m, 3,
                     self.master_doing_election, True)
 
         def thread_client() :
+            self = wr()
             return self.thread_do(self.dbenvClient, self.m2c, 13,
                     self.client_doing_election, False)
 
                                     break
                                 except db.DBRepUnavailError :
                                     pass
+
                         if not election_status[0] and not self.confirmed_master :
                             from threading import Thread
                             election_status[0] = True

File Misc/NEWS

View file
 Extension Modules
 -----------------
 
+- Issue #7808: Fix reference leaks in _bsddb and related tests.
+
 - Stop providing crtassem.h symbols when compiling with Visual Studio 2010, as
   msvcr100.dll is not a platform assembly anymore.
 

File Modules/_bsddb.c

View file
 
 	args = BuildValue_SS(leftKey->data, leftKey->size, rightKey->data, rightKey->size);
 	if (args != NULL) {
-		/* XXX(twouters) I highly doubt this INCREF is correct */
-		Py_INCREF(self);
 		result = PyEval_CallObject(self->btCompareCallback, args);
 	}
 	if (args == NULL || result == NULL) {
     if (result == NULL)
         return NULL;
     if (!NUMBER_Check(result)) {
+	Py_DECREF(result);
 	PyErr_SetString(PyExc_TypeError,
 		        "callback MUST return an int");
 	return NULL;
     } else if (NUMBER_AsLong(result) != 0) {
+	Py_DECREF(result);
 	PyErr_SetString(PyExc_TypeError,
 		        "callback failed to return 0 on two empty strings");
 	return NULL;
             free(listp);
             return NULL;
         }
+        Py_DECREF(key);
+        Py_DECREF(tuple);
     }
     free(listp);
     return stats;
     return PyInit__bsddb();   /* Note the two underscores */
 #endif
 }
-