Browse Source

[object_store] Avoid leaking previous pack when adding known pack

Signed-off-by: Earl Chew <earl_chew@yahoo.com>
Earl Chew 7 years ago
parent
commit
67cda2651b
1 changed files with 5 additions and 1 deletions
  1. 5 1
      dulwich/object_store.py

+ 5 - 1
dulwich/object_store.py

@@ -293,7 +293,11 @@ class PackBasedObjectStore(BaseObjectStore):
         """Add a newly appeared pack to the cache by path.
 
         """
-        self._pack_cache[base_name] = pack
+        prev_pack = self._pack_cache.get(base_name)
+        if prev_pack is not pack:
+            self._pack_cache[base_name] = pack
+            if prev_pack:
+                prev_pack.close()
 
     def _flush_pack_cache(self):
         pack_cache = self._pack_cache