Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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