git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Stefan Beller <sbeller@google.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	Git List <git@vger.kernel.org>,
	knittl89+git@googlemail.com, Xin Jiang <worldhello.net@gmail.com>
Subject: Re: [PATCH V2 4/6] wt-status.c: fix a memleak
Date: Fri, 27 Mar 2015 19:16:08 -0400	[thread overview]
Message-ID: <CAPig+cT8_0+tgcDa4yOPgOLUA8Xtwa26JhMWo84c-J3_bjbTfw@mail.gmail.com> (raw)
In-Reply-To: <1427495569-10863-5-git-send-email-sbeller@google.com>

On Fri, Mar 27, 2015 at 6:32 PM, Stefan Beller <sbeller@google.com> wrote:
> In any code path of shorten_unambiguous_ref the return value is a
> xstrdup(some string), so it is safe to free the variable `base`
> in any codepath.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>  wt-status.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/wt-status.c b/wt-status.c
> index 853419f..9d2a349 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -1576,6 +1576,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
>
>         color_fprintf(s->fp, header_color, "]");
>         fputc(s->null_termination ? '\0' : '\n', s->fp);
> +
> +       free((char *)base);

There's an early 'return' before this point (at line 1560) which will
leak 'base', so this is an unreliable fix.  A better solution would be
to free(base) immediately after it's final use (before the early
'return').

>  }
>
>  void wt_shortstatus_print(struct wt_status *s)
> --
> 2.3.0.81.gc37f363

  reply	other threads:[~2015-03-27 23:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-27 22:32 [PATCH V2 0/6] Memory leaks once again Stefan Beller
2015-03-27 22:32 ` [PATCH V2 1/6] shallow: fix a memleak Stefan Beller
2015-03-27 23:01   ` Eric Sunshine
2015-03-27 22:32 ` [PATCH V2 2/6] line-log.c: " Stefan Beller
2015-03-27 22:32 ` [PATCH V2 3/6] " Stefan Beller
2015-03-27 22:32 ` [PATCH V2 4/6] wt-status.c: " Stefan Beller
2015-03-27 23:16   ` Eric Sunshine [this message]
2015-03-27 22:32 ` [PATCH V2 5/6] pack-bitmap: " Stefan Beller
2015-03-27 23:27   ` Eric Sunshine
2015-03-31  3:29   ` Jeff King
2015-03-27 22:32 ` [PATCH V2 6/6] WIP/RFC/entry.c: " Stefan Beller
2015-03-27 23:32   ` Eric Sunshine
2015-03-28  0:14     ` Eric Sunshine
2015-03-28 11:09       ` John Keeping

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=CAPig+cT8_0+tgcDa4yOPgOLUA8Xtwa26JhMWo84c-J3_bjbTfw@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=knittl89+git@googlemail.com \
    --cc=sbeller@google.com \
    --cc=worldhello.net@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).