[v4,06/24] merge-recursive: future-proof update_file_flags() against memory leaks
diff mbox series

Message ID 20190817184144.32179-7-newren@gmail.com
State New
Headers show
  • Clean up merge API
Related show

Commit Message

Elijah Newren Aug. 17, 2019, 6:41 p.m. UTC
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

Signed-off-by: Elijah Newren <newren@gmail.com>
 merge-recursive.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff mbox series

diff --git a/merge-recursive.c b/merge-recursive.c
index 9622781612..1d4df952e5 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -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);