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. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jul 25, 2024 at 16:12 UTC
d98d9c77e5d9ac0b0663069e05a512037b9279cf
2 files changed
+4
-1
mailmap.c
+3
-1
@@ -201,8 +201,10 @@ static int read_mailmap_blob(struct string_list *map, const char *name)
201
buf = repo_read_object_file(the_repository, &oid, &type, &size);
202
if (!buf)
203
return error("unable to read mailmap object at %s", name);
204
- if (type != OBJ_BLOB)
204
+ if (type != OBJ_BLOB) {
205
+ free(buf);
206
return error("mailmap is not a blob: %s", name);
207
+ }
208
209
read_mailmap_string(map, buf);
210
t/t4203-mailmap.sh
+1
@@ -5,6 +5,7 @@ test_description='.mailmap configurations'
5
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8
+TEST_PASSES_SANITIZE_LEAK=true
9
. ./test-lib.sh
10
11
test_expect_success 'setup commits and contacts file' '