merge-recursive: future-proof update_file_flags() against memory leaks

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>

Elijah Newren committed Aug 17, 2019 at 11:41 UTC f836bf393731e141a289f6b82d549cf0a10a2bcc
1 file changed +5 -3
merge-recursive.c
+5 -3
@@ -934,9 +934,11 @@ static int update_file_flags(struct merge_options *opt,
934 }
935
936 buf = read_object_file(&contents->oid, &type, &size);
937 - if (!buf)
938 - return err(opt, _("cannot read object %s '%s'"),
939 - oid_to_hex(&contents->oid), path);
937 + if (!buf) {
938 + ret = err(opt, _("cannot read object %s '%s'"),
939 + oid_to_hex(&contents->oid), path);
940 + goto free_buf;
941 + }
942 if (type != OBJ_BLOB) {
943 ret = err(opt, _("blob expected for %s '%s'"),
944 oid_to_hex(&contents->oid), path);