Fix memory leak in git_revparse()#7193
Open
bakersdozen123 wants to merge 1 commit intolibgit2:mainfrom
Open
Conversation
If an error occurs when calling `git_revparse_single()` with `revspec->to`, `revspec->from` must be freed, since it was already successfully allocated.
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.
If an error occurs when calling
git_revparse_single()withrevspec->to,revspec->frommust be freed, since it was already successfully allocated.Fixes #7184.
I didn't set
revspec->fromtoNULLafter freeing it, since I don't generally see that pattern throughout the repo.It's possible
revspec->fromwas not being freed on purpose, since the object isn't opaque, and after receiving an error code, the caller can check if it is non-NULLand free it. I leaned more toward making the function atomic, but I can see how the original behavior may be preferred, especially since thegit_revspecdocs explicitly mention that freeingfromandtois up to the caller.If the original behavior is preferred, I could instead add a note to the
git_revparsedocs about this. Something like:Just to highlight that an error does not necessarily mean nothing has been allocated.