From: "René Scharfe" <l.s.r@web.de>
To: Jeff King <peff@peff.net>, Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] fmt-merge-msg: avoid leaking strbuf in shortlog()
Date: Fri, 8 Dec 2017 18:29:31 +0100 [thread overview]
Message-ID: <e1daa2b6-004b-ad66-b84d-84fa70a44baf@web.de> (raw)
In-Reply-To: <20171207212735.GD12850@sigill.intra.peff.net>
Am 07.12.2017 um 22:27 schrieb Jeff King:
> Grepping for "list_append.*detach" shows a few other possible cases in
> transport-helper.c, which I think are leaks.
-- >8 --
Subject: [PATCH] transport-helper: plug strbuf and string_list leaks
Transfer ownership of detached strbufs to string_lists of the
duplicating variety by calling string_list_append_nodup() instead of
string_list_append() to avoid duplicating and then leaking the buffer.
While at it make sure to release the string_list when done;
push_refs_with_export() already does that.
Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
transport-helper.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/transport-helper.c b/transport-helper.c
index bf05a2dcf1..f682e7c534 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -882,7 +882,8 @@ static int push_refs_with_push(struct transport *transport,
struct strbuf cas = STRBUF_INIT;
strbuf_addf(&cas, "%s:%s",
ref->name, oid_to_hex(&ref->old_oid_expect));
- string_list_append(&cas_options, strbuf_detach(&cas, NULL));
+ string_list_append_nodup(&cas_options,
+ strbuf_detach(&cas, NULL));
}
}
if (buf.len == 0) {
@@ -897,6 +898,7 @@ static int push_refs_with_push(struct transport *transport,
strbuf_addch(&buf, '\n');
sendline(data, &buf);
strbuf_release(&buf);
+ string_list_release(&cas_options, 0);
return push_update_refs_status(data, remote_refs, flags);
}
@@ -930,7 +932,8 @@ static int push_refs_with_export(struct transport *transport,
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
if (private && !get_oid(private, &oid)) {
strbuf_addf(&buf, "^%s", private);
- string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
+ string_list_append_nodup(&revlist_args,
+ strbuf_detach(&buf, NULL));
oidcpy(&ref->old_oid, &oid);
}
free(private);
--
2.15.1
next prev parent reply other threads:[~2017-12-08 17:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-07 20:22 [PATCH] fmt-merge-msg: avoid leaking strbuf in shortlog() René Scharfe
2017-12-07 21:27 ` Jeff King
2017-12-08 17:29 ` René Scharfe [this message]
2017-12-08 18:44 ` Junio C Hamano
2017-12-08 20:10 ` René Scharfe
2017-12-08 21:11 ` Jeff King
2017-12-07 21:47 ` Junio C Hamano
2017-12-08 10:14 ` Jeff King
2017-12-08 17:29 ` René Scharfe
2017-12-08 18:37 ` Junio C Hamano
2017-12-08 21:28 ` Jeff King
2017-12-18 19:18 ` René Scharfe
2017-12-19 11:38 ` Jeff King
2017-12-19 18:26 ` René Scharfe
2017-12-20 13:05 ` Jeff King
2017-12-08 21:17 ` 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=e1daa2b6-004b-ad66-b84d-84fa70a44baf@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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).