Fix leaks of RzILMem buffers and clarify ownership of buffer. #5739
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Your checklist for this pull request
RZ_APIfunction and struct this PR changes.RZ_API).Detailed description
The previous assumption of
RzILMemwas that the buffer is not owned by it. This made sense, because in the beginning it only held anRzIObuffer.But the Xtensa and Sparc
RzAnalysisILInitCallbackdefinition initializes an additionalRzILMemobject. This additionalRzILMemhas a sparse buffer in both cases. The Xtensa and Sparc plugin pass the sparse buffer toRzILMemwith the assumption that it is owned. They have to, because there is nofini()version ofRzAnalysisILInitCallbackin which they could free the buffer. There are also no API functions to free the buffer inRzILMem. So the plugins don't have a nice way to clean it up in a theoreticalfini()callback.This commit fixes the leak by adding a flag to
rz_il_mem_new()to mark the ownership of the given buffer.This seems the most natural solution, because buffers can abstract from all kind of backends (
RzIO, a file, some memory etc.). Each time the ownership of the buffer is different. So the creator ofrz_il_mem_new()can decide what buffer with what ownership they pass.Test plan
All green no crashes.
Closing issues
...