{"thread":{"id":"61848","subject":"[PATCH] mailmap: plug memory leak in read_mailmap_blob()","startedAt":"2024-07-25T23:12:44Z","lastAt":"2024-07-26T04:44:05Z","messageCount":2,"participants":["Junio C Hamano","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"499382","messageId":"xmqqcyn112xi.fsf@gitster.g","threadId":"61848","inReplyTo":null,"subject":"[PATCH] mailmap: plug memory leak in read_mailmap_blob()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-25T23:12:41Z","receivedAt":"2024-07-25T23:12:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When a named object to read mailmap from is not a blob, the code\ncorrectly errors out, but it forgot to free the object data before\ndoing so.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n mailmap.c          | 4 +++-\n t/t4203-mailmap.sh | 1 +\n 2 files changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/mailmap.c b/mailmap.c\nindex 2d0212f444..2acf97f307 100644\n--- a/mailmap.c\n+++ b/mailmap.c\n@@ -201,8 +201,10 @@ static int read_mailmap_blob(struct string_list *map, const char *name)\n \tbuf = repo_read_object_file(the_repository, &oid, &type, &size);\n \tif (!buf)\n \t\treturn error(\"unable to read mailmap object at %s\", name);\n-\tif (type != OBJ_BLOB)\n+\tif (type != OBJ_BLOB) {\n+\t\tfree(buf);\n \t\treturn error(\"mailmap is not a blob: %s\", name);\n+\t}\n \n \tread_mailmap_string(map, buf);\n \ndiff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh\nindex 8a88dd7900..79e5f42760 100755\n--- a/t/t4203-mailmap.sh\n+++ b/t/t4203-mailmap.sh\n@@ -5,6 +5,7 @@ test_description='.mailmap configurations'\n GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n+TEST_PASSES_SANITIZE_LEAK=true\n . ./test-lib.sh\n \n test_expect_success 'setup commits and contacts file' '\n-- \n2.46.0-rc2-67-g99767055c1\n\n"},{"id":"499388","messageId":"20240726044403.GB642208@coredump.intra.peff.net","threadId":"61848","inReplyTo":"xmqqcyn112xi.fsf@gitster.g","subject":"Re: [PATCH] mailmap: plug memory leak in read_mailmap_blob()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2024-07-26T04:44:03Z","receivedAt":"2024-07-26T04:44:05Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jul 25, 2024 at 04:12:41PM -0700, Junio C Hamano wrote:\n\n> When a named object to read mailmap from is not a blob, the code\n> correctly errors out, but it forgot to free the object data before\n> doing so.\n> [..]\n> -\tif (type != OBJ_BLOB)\n> +\tif (type != OBJ_BLOB) {\n> +\t\tfree(buf);\n>  \t\treturn error(\"mailmap is not a blob: %s\", name);\n> +\t}\n\nLooks obviously correct. This one is almost certainly my fault.\n\n-Peff\n"}]}