[Yum-devel] [patch] leaking yum.log fd when instantiating multiple YumBase objects

Zdenek Pavlas zpavlas at redhat.com
Fri Jun 17 14:45:51 UTC 2011


Should fix https://bugzilla.redhat.com/show_bug.cgi?id=713924
Very ugly, I know, but it seems to work.  Any better ideas?
Turn 'cleanup' to '_cleanup'?

--- yum-3.4.1/yum/__init__.py.old	2011-06-17 16:31:49.014599854 +0200
+++ yum-3.4.1/yum/__init__.py	2011-06-17 16:36:23.355599854 +0200
@@ -203,11 +203,13 @@ class YumBase(depsolve.Depsolve):
         self.prerepoconf = _YumPreRepoConf()
 
         self.run_with_package_names = set()
+        self.cleanup = []
 
     def __del__(self):
         self.close()
         self.closeRpmDB()
         self.doUnlock()
+        [i() for i in self.cleanup] # close leaks
 
     def close(self):
         # We don't want to create the object, so we test if it's been created
@@ -375,7 +377,7 @@ class YumBase(depsolve.Depsolve):
                                      syslog_device)
 
     def doFileLogSetup(self, uid, logfile):
-        logginglevels.setFileLog(uid, logfile)
+        logginglevels.setFileLog(uid, logfile, self.cleanup)
 
     def getReposFromConfigFile(self, repofn, repo_age=None, validate=None):
         """read in repositories from a config .repo file"""
diff -up yum-3.4.1/yum/logginglevels.py.old yum-3.4.1/yum/logginglevels.py
--- yum-3.4.1/yum/logginglevels.py.old	2011-06-17 16:32:03.860599957 +0200
+++ yum-3.4.1/yum/logginglevels.py	2011-06-17 16:38:33.906599869 +0200
@@ -186,7 +186,7 @@ def doLoggingSetup(debuglevel, errorleve
     if errorlevel is not None:  
         setErrorLevel(errorlevel)
 
-def setFileLog(uid, logfile):
+def setFileLog(uid, logfile, cleanup = []):
     # TODO: When python's logging config parser doesn't blow up
     # when the user is non-root, put this in the config file.
     # syslog-style log
@@ -208,6 +208,8 @@ def setFileLog(uid, logfile):
                 "%b %d %H:%M:%S")
             filehandler.setFormatter(formatter)
             filelogger.addHandler(filehandler)
+	    # closes the logfile when YumBase gets recycled
+	    cleanup.append(lambda: filelogger.removeHandler(filehandler))
         except IOError:
             logging.getLogger("yum").critical('Cannot open logfile %s', logfile)
 
--
Zdenek



More information about the Yum-devel mailing list