summaryrefslogtreecommitdiffstats
path: root/config.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-08-14 08:52:14 +0200
committerJunio C Hamano <gitster@pobox.com>2024-08-14 19:07:58 +0200
commit648abbe22d55a6004bf6dafa7c0ed209572c9fe9 (patch)
treeb95fe9852fc035c286edc275095d41869c7ffdf2 /config.c
parentsubmodule-config: fix leaking name entry when traversing submodules (diff)
downloadgit-648abbe22d55a6004bf6dafa7c0ed209572c9fe9.tar.xz
git-648abbe22d55a6004bf6dafa7c0ed209572c9fe9.zip
config: fix leaking comment character config
When the comment line character has been specified multiple times in the configuration, then `git_default_core_config()` will cause a memory leak because it unconditionally copies the string into `comment_line_str` without free'ing the previous value. In fact, it can't easily free the value in the first place because it may contain a string constant. Refactor the code such that we track allocated comment character strings via a separate non-constant variable `comment_line_str_to_free`. Adapt sites that set `comment_line_str` to set both and free the old value that was stored in `comment_line_str_to_free`. This memory leak is being hit in t3404. As there are still other memory leaks in that file we cannot yet mark it as passing with leak checking enabled. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/config.c b/config.c
index 6421894614..205660a8fb 100644
--- a/config.c
+++ b/config.c
@@ -1596,7 +1596,8 @@ static int git_default_core_config(const char *var, const char *value,
else if (value[0]) {
if (strchr(value, '\n'))
return error(_("%s cannot contain newline"), var);
- comment_line_str = xstrdup(value);
+ comment_line_str = value;
+ FREE_AND_NULL(comment_line_str_to_free);
auto_comment_line_char = 0;
} else
return error(_("%s must have at least one character"), var);