Skip to content

Commit

Permalink
fix(leaks): attempt to plug the leaks & filter dead regions
Browse files Browse the repository at this point in the history
Possible fixing gitpython-developers#31 double mmap increment, stop decrement on
destruction, rely on with... resources.
  • Loading branch information
ankostis committed Oct 24, 2016
1 parent 2347f3d commit 6f46079
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 1 addition & 6 deletions smmap/mman.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ def __init__(self, manager=None, regions=None):
self._ofs = 0
self._size = 0

def __del__(self):
self._destroy()

def __enter__(self):
return self

Expand Down Expand Up @@ -133,8 +130,6 @@ def use_region(self, offset=0, size=0, flags=0):

if need_region:
self._region = man._obtain_region(self._rlist, offset, size, flags, False)
self._region.increment_client_count()
# END need region handling

self._ofs = offset - self._region._b
self._size = min(size, self._region.ofs_end() - offset)
Expand Down Expand Up @@ -401,7 +396,7 @@ def make_cursor(self, path_or_fd):
**Note:** Using file descriptors directly is faster once new windows are mapped as it
prevents the file to be opened again just for the purpose of mapping it."""
regions = self._fdict.get(path_or_fd)
if regions is None:
if not regions or not regions.filter_closed():
regions = self.MapRegionListCls(path_or_fd)
self._fdict[path_or_fd] = regions
# END obtain region for path
Expand Down
6 changes: 6 additions & 0 deletions smmap/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,10 @@ def file_size(self):
# END update file size
return self._file_size

def filter_closed(self):
for r in list(self):
if r._mf.closed:
self.remove(r)
return self

#} END utility classes

0 comments on commit 6f46079

Please sign in to comment.