Skip to content

Commit

Permalink
fix memory leak parsing core.commentchar
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jul 24, 2014
1 parent def0697 commit 649409b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,11 +824,11 @@ static int git_default_core_config(const char *var, const char *value)
return git_config_string(&editor_program, var, value);

if (!strcmp(var, "core.commentchar")) {
const char *comment;
int ret = git_config_string(&comment, var, value);
if (!ret)
comment_line_char = comment[0];
return ret;
if (!value)
return config_error_nonbool(var);
else
comment_line_char = value[0];
return 0;
}

if (!strcmp(var, "core.askpass"))
Expand Down

0 comments on commit 649409b

Please sign in to comment.