Skip to contentSkip to conversation

mailmap: plug memory leak in read_mailmap_blob()

PATCH In review Junio C Hamano 2 participants 2 messages Jul 25, 2024 – Jul 26, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mailmap: plug memory leak in read_mailmap_blob()

When a named object to read mailmap from is not a blob, the code correctly errors out, but it forgot to free the object data before doing so.

---
 mailmap.c          | 4 +++-
 t/t4203-mailmap.sh | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
mailmap.c +3 -1
index 2d0212f444..2acf97f307 100644
@@ -201,8 +201,10 @@ static int read_mailmap_blob(struct string_list *map, const char *name)
 	buf = repo_read_object_file(the_repository, &oid, &type, &size);
 	if (!buf)
 		return error("unable to read mailmap object at %s", name);
-	if (type != OBJ_BLOB)
+	if (type != OBJ_BLOB) {
+		free(buf);
 		return error("mailmap is not a blob: %s", name);
+	}
 
 	read_mailmap_string(map, buf);
 
t/t4203-mailmap.sh +1 -0
index 8a88dd7900..79e5f42760 100755
@@ -5,6 +5,7 @@ test_description='.mailmap configurations'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup commits and contacts file' '
Signature · 1 line
2.46.0-rc2-67-g99767055c1
#1 lore raw

mailmap.c static int read_mailmap_blob(struct string_list *map, const char *name) · line 207

Quoted 9 lines · Junio C Hamano

When a named object to read mailmap from is not a blob, the code correctly errors out, but it forgot to free the object data before doing so.
[..]

mailmap.c +3 -1
-	if (type != OBJ_BLOB)
+	if (type != OBJ_BLOB) {
+		free(buf);
 		return error("mailmap is not a blob: %s", name);
+	}

Looks obviously correct. This one is almost certainly my fault.

-Peff