Fix error handling string memory leak#18
Open
jecassis wants to merge 1 commit intoprojectM-visualizer:masterfrom
Open
Fix error handling string memory leak#18jecassis wants to merge 1 commit intoprojectM-visualizer:masterfrom
jecassis wants to merge 1 commit intoprojectM-visualizer:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Through the use of the CRT debugger while developing foo_vis_milk2 I uncovered a small heap leak in the error handling which is not releasing the previous parser error string before storing a new one.
In "CompilerFunctions.c",
prjm_eval_error()duplicates each parse error message with_strdup()and assigns it tocctx->error.error.When multiple parse errors occur in the same compile context, each new assignment overwrites the previous pointer without freeing it first.
Here is the CRT output (on Windows):
I tested the following fix:
Before assigning a new error message, it frees the previous
cctx->error.errorinprjm_eval_error(). Consequently, each new parser error replaces the previous message without losing ownership of allocated memory.This should result in no functional behavior delta and, since making this change, I have not seen the memory leaks reoccurring.