fix memory leak parsing core.commentchar

When we see the core.commentchar config option, we extract the string with git_config_string, which does two things: 1. It complains via config_error_nonbool if there is no string value. 2. It makes a copy of the string. Since we immediately parse the string into its single-character value, we only care about (1). And in fact (2) is a detriment, as it means we leak the copy. Instead, let's just check the pointer value ourselves, and parse directly from the const string we already have. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 24, 2014 at 00:42 UTC 649409b7bccdcd6d6e5273b2b7340cea05f77736
1 file changed +5 -5
config.c
+5 -5
@@ -824,11 +824,11 @@ static int git_default_core_config(const char *var, const char *value)
824 return git_config_string(&editor_program, var, value);
825
826 if (!strcmp(var, "core.commentchar")) {
827 - const char *comment;
828 - int ret = git_config_string(&comment, var, value);
829 - if (!ret)
830 - comment_line_char = comment[0];
831 - return ret;
827 + if (!value)
828 + return config_error_nonbool(var);
829 + else
830 + comment_line_char = value[0];
831 + return 0;
832 }
833
834 if (!strcmp(var, "core.askpass"))