Skip to content

Commit 649409b

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent def0697 commit 649409b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

config.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -824,11 +824,11 @@ static int git_default_core_config(const char *var, const char *value)
824824
return git_config_string(&editor_program, var, value);
825825

826826
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;
832832
}
833833

834834
if (!strcmp(var, "core.askpass"))

0 commit comments

Comments
 (0)