[PATCH v3 21/27] mailmap: always store allocated strings in mailmap blob
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Jun 3, 2024, 09:40 UTC
- Message-ID
- <fb240598b4ecc5b64069c5e7bd8cd9f71d16b564.1717402403.git.ps@pks.im>
- In-Reply-To
- <cover.1717402403.git.ps@pks.im>
Same as with the preceding commit, the `git_mailmap_blob` may sometimes contain an allocated string and sometimes it may contain a string constant. This is risky and can easily lead to bugs in case the variable is getting re-assigned, where the code may then try to free the previous value to avoid memory leaks.
Safeguard the code by always storing allocated strings in the variable.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- mailmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mailmap.c b/mailmap.c index b2efe29b3d..3d1e092fef 100644 --- a/mailmap.c +++ b/mailmap.c @@ -216,7 +216,7 @@ int read_mailmap(struct string_list *map) map->cmp = namemap_cmp; if (!git_mailmap_blob && is_bare_repository()) - git_mailmap_blob = "HEAD:.mailmap"; + git_mailmap_blob = xstrdup("HEAD:.mailmap"); if (!startup_info->have_repository || !is_bare_repository()) err |= read_mailmap_file(map, ".mailmap",
-- 2.45.1.410.g58bac47f8e.dirty