[pysnmp-dev] Unclosed files in pysmnp.smi.builder
Brought to you by:
elie
From: Zachary W. <zac...@gm...> - 2014-10-25 22:07:26
|
Hi, Currently, DirMibSource._getData doesn't close the files it opens, leading to a flood of ResourceWarnings (when warnings are enabled on a sufficiently recent CPython). The following simple patch ought to be sufficient to fix it for all supported Python versions. Regards, -- Zach (Patch also attached in case Gmail decides to mess things up one way or the other) Index: pysnmp/smi/builder.py =================================================================== RCS file: /cvsroot/pysnmp/pysnmp/pysnmp/smi/builder.py,v retrieving revision 1.51 diff -u -r1.51 builder.py --- pysnmp/smi/builder.py 4 Jun 2013 06:06:23 -0000 1.51 +++ pysnmp/smi/builder.py 25 Oct 2014 22:00:04 -0000 @@ -162,7 +162,11 @@ def _getData(self, f, mode): try: if f in os.listdir(self._srcName): # make FS case-sensitive - return open(os.path.join(self._srcName, f), mode).read() + fp = open(os.path.join(self._srcName, f), mode) + try: + return fp.read() + finally: + fp.close() except OSError: pass raise IOError # pretend there's no such file |