diff_file: properly refcount blobs when initializing file contents#4447
Merged
ethomson merged 1 commit intoDec 16, 2017
Merged
Conversation
When initializing a `git_diff_file_content` from a source whose data is derived from a blob, we simply assign the blob's pointer to the resulting struct without incrementing its refcount. Thus, the structure can only be used as long as the blob is kept alive by the caller. Fix the issue by using `git_blob_dup` instead of a direct assignment. This function will increment the refcount of the blob without allocating new memory, so it does exactly what we want. As `git_diff_file_content__unload` already frees the blob when `GIT_DIFF_FLAG__FREE_BLOB` is set, we don't need to add new code handling the free but only have to set that flag correctly.
Member
Author
|
This should probably fix #4442. The test case I added didn't trigger any faults locally at my machine, so I'm not certain that it actually tests what I'd like it to test. |
|
Thanks for the quick fix! The changes and included test LGTM! I'll later test to ensure that this fixes the problem |
|
Just tested it on my machine! Without the fix: With the fix, all tests pass. It looks good to me! Let's merge this in! |
Member
|
Looks good to me. 😁 Thanks @brandonio21 for debugging and the helpful bug report; thanks @pks-t for the fix. |
Merged
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.
When initializing a
git_diff_file_contentfrom a source whose data isderived from a blob, we simply assign the blob's pointer to the
resulting struct without incrementing its refcount. Thus, the structure
can only be used as long as the blob is kept alive by the caller.
Fix the issue by using
git_blob_dupinstead of a direct assignment.This function will increment the refcount of the blob without allocating
new memory, so it does exactly what we want. As
git_diff_file_content__unloadalready frees the blob whenGIT_DIFF_FLAG__FREE_BLOBis set, we don't need to add new codehandling the free but only have to set that flag correctly.