builtin/help: fix leaking `html_path` when reading config multiple times

The `html_path` variable gets populated via `git_help_config()`, which puts an allocated string into it if its value has been configured. We do not clear the old value though, which causes a memory leak in case the config exists multiple times. Plug this leak. The leak is exposed by t0012, but plugging it alone is not sufficient to make the test suite pass. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Sep 26, 2024 at 13:46 UTC 0f26223b6de6ac3a2e514bb306fef29f34970465
1 file changed +2 -1
builtin/help.c
+2 -1
@@ -52,7 +52,7 @@ static enum help_action {
52 HELP_ACTION_CONFIG_SECTIONS_FOR_COMPLETION,
53 } cmd_mode;
54
55 -static const char *html_path;
55 +static char *html_path;
56 static int verbose = 1;
57 static enum help_format help_format = HELP_FORMAT_NONE;
58 static int exclude_guides;
@@ -409,6 +409,7 @@ static int git_help_config(const char *var, const char *value,
409 if (!strcmp(var, "help.htmlpath")) {
410 if (!value)
411 return config_error_nonbool(var);
412 + free(html_path);
413 html_path = xstrdup(value);
414 return 0;
415 }