From: Junio C Hamano <gitster@pobox.com>
To: Kevin Willford <kewillf@microsoft.com>
Cc: git@vger.kernel.org, peff@peff.net, peartben@gmail.com
Subject: Re: [PATCH 2/3] read-cache: fix memory leak in do_write_index
Date: Mon, 21 Aug 2017 16:02:53 -0700 [thread overview]
Message-ID: <xmqq1so45xsy.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170821212432.47364-3-kewillf@microsoft.com> (Kevin Willford's message of "Mon, 21 Aug 2017 15:24:31 -0600")
Kevin Willford <kewillf@microsoft.com> writes:
> The previous_name_buf was never getting released when there
> was an error in ce_write_entry or allow was false and execution
> was returned to the caller.
>
> Signed-off-by: Kevin Willford <kewillf@microsoft.com>
> ---
Thanks for spotting an old error that dates back to at least 2013
this month. The patch looks sensible.
> read-cache.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index acfb028f48..47220cc30d 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -2192,7 +2192,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
> int newfd = tempfile->fd;
> git_SHA_CTX c;
> struct cache_header hdr;
> - int i, err, removed, extended, hdr_version;
> + int i, err = 0, removed, extended, hdr_version;
> struct cache_entry **cache = istate->cache;
> int entries = istate->cache_nr;
> struct stat st;
> @@ -2247,15 +2247,21 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
> if (allow)
> warning(msg, ce->name);
> else
> - return error(msg, ce->name);
> + err = error(msg, ce->name);
>
> drop_cache_tree = 1;
> }
> if (ce_write_entry(&c, newfd, ce, previous_name) < 0)
> - return -1;
> + err = -1;
> +
> + if (err)
> + break;
> }
> strbuf_release(&previous_name_buf);
>
> + if (err)
> + return err;
> +
> /* Write extension data here */
> if (!strip_extensions && istate->split_index) {
> struct strbuf sb = STRBUF_INIT;
next prev parent reply other threads:[~2017-08-21 23:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-21 21:24 [PATCH 0/3] read-cache: use stack ondisk struct when writing index Kevin Willford
2017-08-21 21:24 ` [PATCH 1/3] perf: add test for writing the index Kevin Willford
2017-08-21 21:24 ` [PATCH 2/3] read-cache: fix memory leak in do_write_index Kevin Willford
2017-08-21 23:02 ` Junio C Hamano [this message]
2017-08-21 21:24 ` [PATCH 3/3] read-cache: avoid allocating every ondisk entry when writing Kevin Willford
2017-08-21 23:42 ` Junio C Hamano
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=xmqq1so45xsy.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=kewillf@microsoft.com \
--cc=peartben@gmail.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.
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).