From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Stefan Beller <stefanbeller@gmail.com>
Subject: [PATCH 4/5] fix memory leak parsing core.commentchar
Date: Thu, 24 Jul 2014 00:42:39 -0400 [thread overview]
Message-ID: <20140724044239.GD32355@peff.net> (raw)
In-Reply-To: <20140724043940.GA31282@peff.net>
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>
---
config.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/config.c b/config.c
index 9767c4b..058505c 100644
--- a/config.c
+++ b/config.c
@@ -817,14 +817,12 @@ 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)
- return ret;
- else if (!strcasecmp(comment, "auto"))
+ if (!value)
+ return config_error_nonbool(var);
+ else if (!strcasecmp(value, "auto"))
auto_comment_line_char = 1;
- else if (comment[0] && !comment[1]) {
- comment_line_char = comment[0];
+ else if (value[0] && !value[1]) {
+ comment_line_char = value[0];
auto_comment_line_char = 0;
} else
return error("core.commentChar should only be one character");
--
2.0.0.566.gfe3e6b2
next prev parent reply other threads:[~2014-07-24 4:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-24 4:39 [PATCH 0/5] coverity mixed bag Jeff King
2014-07-24 4:40 ` [PATCH 1/5] receive-pack: don't copy "dir" parameter Jeff King
2014-07-24 4:41 ` [PATCH 2/5] free ref string returned by dwim_ref Jeff King
2014-07-24 4:41 ` [PATCH 3/5] transport: fix leaks in refs_from_alternate_cb Jeff King
2014-07-24 4:42 ` Jeff King [this message]
2014-07-24 4:43 ` [PATCH 5/5] apply: avoid possible bogus pointer Jeff King
2014-07-24 20:33 ` [PATCH 0/5] coverity mixed bag Junio C Hamano
2014-07-29 5:36 ` Stefan Beller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140724044239.GD32355@peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=stefanbeller@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).