Skip to content

Commit

Permalink
merge-recursive: future-proof update_file_flags() against memory leaks
Browse files Browse the repository at this point in the history
There is a 'free_buf' label to which all but one of the error paths in
update_file_flags() jump; that error case involves a NULL buf and is
thus not a memory leak.  However, make that error case execute the same
deallocation code anyway so that if anyone adds any additional memory
allocations or deallocations, then all error paths correctly deallocate
resources.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
newren authored and gitster committed Aug 19, 2019
1 parent 8e01251 commit f836bf3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions merge-recursive.c
Expand Up @@ -934,9 +934,11 @@ static int update_file_flags(struct merge_options *opt,
}

buf = read_object_file(&contents->oid, &type, &size);
if (!buf)
return err(opt, _("cannot read object %s '%s'"),
oid_to_hex(&contents->oid), path);
if (!buf) {
ret = err(opt, _("cannot read object %s '%s'"),
oid_to_hex(&contents->oid), path);
goto free_buf;
}
if (type != OBJ_BLOB) {
ret = err(opt, _("blob expected for %s '%s'"),
oid_to_hex(&contents->oid), path);
Expand Down

0 comments on commit f836bf3

Please sign in to comment.