Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit efb49f8

Browse files
committed
Keep path references in merge_file_from_index
IndexEntry._to_c requires its caller to hold a reference to the path it returns until it no longer needs the C structure. Repository.merge_file_from_index was not doing so, causing the merge text to contain garbage from freed memory in some cases.
1 parent f923e20 commit efb49f8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pygit2/repository.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,12 @@ def merge_file_from_index(self, ancestor, ours, theirs):
551551
"""
552552
cmergeresult = ffi.new('git_merge_file_result *')
553553

554-
cancestor = ancestor._to_c()[0] if ancestor is not None else ffi.NULL
555-
cours = ours._to_c()[0] if ours is not None else ffi.NULL
556-
ctheirs = theirs._to_c()[0] if theirs is not None else ffi.NULL
554+
cancestor, ancestor_str_ref = (
555+
ancestor._to_c() if ancestor is not None else (ffi.NULL, ffi.NULL))
556+
cours, ours_str_ref = (
557+
ours._to_c() if ours is not None else (ffi.NULL, ffi.NULL))
558+
ctheirs, theirs_str_ref = (
559+
theirs._to_c() if theirs is not None else (ffi.NULL, ffi.NULL))
557560

558561
err = C.git_merge_file_from_index(
559562
cmergeresult, self._repo,

0 commit comments

Comments
 (0)