mailmap: xcalloc mailmap_info

This is to avoid reaching free of uninitialized members. With an invalid .mailmap (and perhaps in other cases), it can reach free(mi->name) with garbage for example. Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Marc-André Lureau committed Nov 17, 2011 at 02:25 UTC 74b531f65feaa09b5c3963f788b437a368933730
1 file changed +2 -3
mailmap.c
+2 -3
@@ -61,8 +61,7 @@ static void add_mapping(struct string_list *map,
61 } else {
62 /* create mailmap entry */
63 struct string_list_item *item = string_list_insert_at_index(index, old_email, map);
64 - item->util = xmalloc(sizeof(struct mailmap_entry));
65 - memset(item->util, 0, sizeof(struct mailmap_entry));
64 + item->util = xcalloc(1, sizeof(struct mailmap_entry));
65 ((struct mailmap_entry *)item->util)->namemap.strdup_strings = 1;
66 }
67 me = (struct mailmap_entry *)map->items[index].util;
@@ -77,7 +76,7 @@ static void add_mapping(struct string_list *map,
76 if (new_email)
77 me->email = xstrdup(new_email);
78 } else {
80 - struct mailmap_info *mi = xmalloc(sizeof(struct mailmap_info));
79 + struct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info));
80 debug_mm("mailmap: adding (complex) entry for %s at index %d\n", old_email, index);
81 if (new_name)
82 mi->name = xstrdup(new_name);