Skip to content

Commit 7d4053b

Browse files
committed
rerere: do not leak mmfile[] for a path with multiple stage #1 entries
A conflicted index can have multiple stage #1 entries when dealing with a criss-cross merge and using the "resolve" merge strategy. Plug the leak by reading only the first one of the same stage entries. Strictly speaking, this fix does change the semantics, in that we used to use the last stage #1 entry as the common ancestor when doing the plain-vanilla three-way merge, but with the leak fix, we will use the first stage #1 entry. But it is not a grave backward compatibility breakage. Either way, we are arbitrarily picking one of multiple stage #1 entries and using it, ignoring others, and there is no meaning in the ordering of these stage #1 entries. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 74444d4 commit 7d4053b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

rerere.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,10 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
337337
if (ce_namelen(ce) != len || memcmp(ce->name, path, len))
338338
break;
339339
i = ce_stage(ce) - 1;
340-
mmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size);
341-
mmfile[i].size = size;
340+
if (!mmfile[i].ptr) {
341+
mmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size);
342+
mmfile[i].size = size;
343+
}
342344
}
343345
for (i = 0; i < 3; i++)
344346
if (!mmfile[i].ptr && !mmfile[i].size)

0 commit comments

Comments
 (0)