Skip to content

Commit

Permalink
Fix memory leak when breaking mid-way in _get_objects and _get_ids (#266
Browse files Browse the repository at this point in the history
)

* Fix memory leak when breaking mid-way in _get_objects and _get_ids

* Fix lint error
  • Loading branch information
akariv authored Jun 23, 2023
1 parent 9740c82 commit cd5ac27
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions rtree/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,10 +922,8 @@ def _get_objects(self, it, num_results, objects):
else:
yield self.loads(data)

finally:
core.rt.Index_DestroyObjResults(its, num_results)
except Exception: # need to catch all exceptions, not just rtree.
core.rt.Index_DestroyObjResults(its, num_results)
raise

def _get_ids(self, it, num_results):
# take the pointer, yield the results and free
Expand All @@ -935,10 +933,9 @@ def _get_ids(self, it, num_results):
try:
for i in range(num_results):
yield items.contents[i]

finally:
core.rt.Index_Free(its)
except Exception:
core.rt.Index_Free(its)
raise

def _nearest_obj(self, coordinates, num_results, objects):
p_mins, p_maxs = self.get_coordinate_pointers(coordinates)
Expand Down

0 comments on commit cd5ac27

Please sign in to comment.