summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-07-24 04:42:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-07-24 20:57:50 (GMT)
commit649409b7bccdcd6d6e5273b2b7340cea05f77736 (patch)
treefaa5aa7250f73b18ce9e08b044f726f9c9bb7e21 /config.c
parentdef0697167d0b3fb3c9cc1a2fcbac56e540aae48 (diff)
downloadgit-649409b7bccdcd6d6e5273b2b7340cea05f77736.zip
git-649409b7bccdcd6d6e5273b2b7340cea05f77736.tar.gz
git-649409b7bccdcd6d6e5273b2b7340cea05f77736.tar.bz2
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>
Diffstat (limited to 'config.c')
-rw-r--r--config.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/config.c b/config.c
index a30cb5c..40799a1 100644
--- a/config.c
+++ b/config.c
@@ -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"))