From: Jeff King <peff@peff.net>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Duy Nguyen <pclouds@gmail.com>,
Git Mailing List <git@vger.kernel.org>
Subject: [PATCH] blame: drop strdup of string literal
Date: Tue, 2 Aug 2016 06:52:53 -0400 [thread overview]
Message-ID: <20160802105252.jyl5x7eanttw2swj@sigill.intra.peff.net> (raw)
In-Reply-To: <20160614050541.GA9909@sigill.intra.peff.net>
On Tue, Jun 14, 2016 at 01:05:41AM -0400, Jeff King wrote:
> On Tue, Jun 14, 2016 at 12:32:15AM -0400, Eric Sunshine wrote:
>
> > > + struct string_list range_list = STRING_LIST_INIT_NODUP;
> >
> > Related to this series, there's an additional "fix" which ought to be
> > made, probably as a separate patch. In particular, in cmd_blame():
> >
> > if (lno && !range_list.nr)
> > string_list_append(&range_list, xstrdup("1"));
> >
> > which supplies a default range ("line 1 through end of file") if -L
> > was not specified. I used xstrdup() on the literal "1" in 58dbfa2
> > (blame: accept multiple -L ranges, 2013-08-06) to be consistent with
> > parse_opt_string_list() which was unconditionally xstrdup'ing the
> > argument (but no longer does as of patch 1/3 of this series).
>
> Yeah, I'd agree that this is a minor bug both before and after the
> series due to the leak. Want to roll a patch on top?
Here it is, just to tie up a loose end. I marked you as the author since
the hard part was noticing the issue and explaining the history, which
you already did above.
-- >8 --
From: Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH] blame: drop strdup of string literal
This strdup was added as part of 58dbfa2 (blame: accept
multiple -L ranges, 2013-08-06) to be consistent with
parse_opt_string_list(), which appends to the same list.
But as of 7a7a517 (parse_opt_string_list: stop allocating
new strings, 2016-06-13), we should stop using strdup (to
match parse_opt_string_list, and for all the reasons
described in that commit; namely that it does nothing useful
and causes us to leak the memory).
Signed-off-by: Jeff King <peff@peff.net>
---
builtin/blame.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index ab66cde..29bd479 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2805,7 +2805,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
lno = prepare_lines(&sb);
if (lno && !range_list.nr)
- string_list_append(&range_list, xstrdup("1"));
+ string_list_append(&range_list, "1");
anchor = 1;
range_set_init(&ranges, range_list.nr);
--
2.9.2.670.g42e63de
next prev parent reply other threads:[~2016-08-02 10:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-10 11:57 [PATCH] parse-options-cb.c: use string_list_append_nodup in OPT_STRING_LIST() Nguyễn Thái Ngọc Duy
2016-06-12 22:03 ` Jeff King
2016-06-13 0:08 ` Duy Nguyen
2016-06-13 5:32 ` [PATCH 0/3] fix parse-opt string_list leaks Jeff King
2016-06-13 5:39 ` [PATCH 1/3] parse_opt_string_list: stop allocating new strings Jeff King
2016-06-13 5:39 ` [PATCH 2/3] interpret-trailers: don't duplicate option strings Jeff King
2016-06-13 5:39 ` [PATCH 3/3] blame,shortlog: don't make local option variables static Jeff King
2016-06-14 4:32 ` Eric Sunshine
2016-06-14 5:05 ` Jeff King
2016-08-02 10:52 ` Jeff King [this message]
2016-08-03 7:36 ` [PATCH] blame: drop strdup of string literal Eric Sunshine
2016-06-13 9:36 ` [PATCH 0/3] fix parse-opt string_list leaks Duy Nguyen
2016-06-13 10:04 ` [PATCH 4/3] use string_list initializer consistently Jeff King
2016-06-13 11:31 ` Duy Nguyen
2016-06-13 17:32 ` Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160802105252.jyl5x7eanttw2swj@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
--cc=sunshine@sunshineco.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).