← Back to team overview

dulwich-users team mailing list archive

[PATCH v2 3/6] pack.FilePackIndex: close mmap object

 

_load_file_contents may return a mmap object, so self._contents could be
mmap-ed. Close it if so.

Note: we use hasattr() instead of isinstance() for pre-Python 2.6
compatibility (mmap became a class in Python 2.6).
---
 dulwich/pack.py |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/dulwich/pack.py b/dulwich/pack.py
index 0654e67..0f17497 100644
--- a/dulwich/pack.py
+++ b/dulwich/pack.py
@@ -360,6 +360,8 @@ class FilePackIndex(PackIndex):
 
     def close(self):
         self._file.close()
+        if getattr(self._contents, "close", None) is not None:
+            self._contents.close()
 
     def __len__(self):
         """Return the number of entries in this pack index."""
-- 
1.7.3.2.msysgit.0




Follow ups

References