Skip to content

Fix memory leak in ManagedRaster#484

Open
emlys wants to merge 5 commits intonatcap:mainfrom
emlys:bugfix/483
Open

Fix memory leak in ManagedRaster#484
emlys wants to merge 5 commits intonatcap:mainfrom
emlys:bugfix/483

Conversation

@emlys
Copy link
Copy Markdown
Member

@emlys emlys commented Apr 29, 2026

Fixes #483
This fixes a couple of memory leaks:

In the next method of the NeighborIterator classes, we allocate memory for a new NeighborTuple to store the current value, and delete the old NeighborTuple. If a NeighborIterator wasn't iterated all the way to the end, the final NeighborTuple would never get deleted. I added a destructor to NeighborIterator that deletes the final NeighborTuple if necessary.

Also, the geotransform attribute was not being freed. This was pretty minor since there's only one of them per ManagedRaster instance.

I tested this by building natcap.invest against this branch of pygeoprocessing, running SDR on the sample data with valgrind, and observing that there are no longer any loss records that mention ManagedRaster.h.

@emlys emlys marked this pull request as ready for review May 6, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak in ManagedRaster

1 participant