]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mailmap.c: fix a memory leak in free_mailap_{info,entry}()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 31 Aug 2021 13:42:52 +0000 (15:42 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 Aug 2021 19:38:09 +0000 (12:38 -0700)
In the free_mailmap_entry() code added in 0925ce4d49 (Add map_user()
and clear_mailmap() to mailmap, 2009-02-08) the intent was clearly to
clear the "me" structure, but while we freed parts of the
mailmap_entry structure, we didn't free the structure itself. The same
goes for the "mailmap_info" structure.

This brings the number of SANITIZE=leak failures in t4203-mailmap.sh
down from 50 to 49. Not really progress as far as the number of
failures is concerned, but as far as I can tell this fixes all leaks
in mailmap.c itself. There's still users of it such as builtin/log.c
that call read_mailmap() without a clear_mailmap(), but that's on
them.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
mailmap.c

index d1f7c0d272d81ca00bfef33c80a02b9d7da997cf..e1c87360938e40a83a422b54d6661ca9b62fb506 100644 (file)
--- a/mailmap.c
+++ b/mailmap.c
@@ -36,6 +36,7 @@ static void free_mailmap_info(void *p, const char *s)
                 s, debug_str(mi->name), debug_str(mi->email));
        free(mi->name);
        free(mi->email);
+       free(mi);
 }
 
 static void free_mailmap_entry(void *p, const char *s)
@@ -51,6 +52,7 @@ static void free_mailmap_entry(void *p, const char *s)
 
        me->namemap.strdup_strings = 1;
        string_list_clear_func(&me->namemap, free_mailmap_info);
+       free(me);
 }
 
 /*