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>
This commit is contained in:
Jeff King 2014-07-24 00:42:39 -04:00 committed by Junio C Hamano
parent def0697167
commit 649409b7bc

View File

@ -824,11 +824,11 @@ static int git_default_core_config(const char *var, const char *value)
return git_config_string(&editor_program, var, value); return git_config_string(&editor_program, var, value);
if (!strcmp(var, "core.commentchar")) { if (!strcmp(var, "core.commentchar")) {
const char *comment; if (!value)
int ret = git_config_string(&comment, var, value); return config_error_nonbool(var);
if (!ret) else
comment_line_char = comment[0]; comment_line_char = value[0];
return ret; return 0;
} }
if (!strcmp(var, "core.askpass")) if (!strcmp(var, "core.askpass"))