All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Stefan Beller <sbeller@google.com>
Cc: gitster@pobox.com, git@vger.kernel.org, tanoku@gmail.com, blees@dcon.de
Subject: Re: [PATCH V2 5/6] pack-bitmap: fix a memleak
Date: Mon, 30 Mar 2015 23:29:53 -0400	[thread overview]
Message-ID: <20150331032953.GA842@peff.net> (raw)
In-Reply-To: <1427495569-10863-6-git-send-email-sbeller@google.com>

On Fri, Mar 27, 2015 at 03:32:48PM -0700, Stefan Beller wrote:

> `recent_bitmaps` is allocated in the function load_bitmap_entries_v1
> and it is not passed into any function, so it's safe to free it before
> leaving that function.

I think this is OK, though it might be easier still to just turn the
array into a stack variable. It's only 160 * sizeof(ptr), or about 1280
bytes on a 64-bit system. Note that the xcalloc there looks wrong (it is
way over-allocating by using the sizeof the struct, not a pointer to the
struct).

> Notes:
>     I wonder however if we need to free the actual bitmaps
>     stored in the recent_bitmaps as well.

No, those are just weak pointers. The memory is owned by the hash that
store_bitmap puts the bitmaps into.

>  		bitmap = read_bitmap_1(index);

This line allocates, too. So if we get down to...

> -		if (xor_offset > MAX_XOR_OFFSET || xor_offset > i)
> -			return error("Corrupted bitmap pack index");
> +		if (xor_offset > MAX_XOR_OFFSET || xor_offset > i) {
> +			ret = error("Corrupted bitmap pack index");
> +			goto out;
> +		}

...here, for example, where we have not yet called store_bitmap, then
it's a leak, too.

-Peff

  parent reply	other threads:[~2015-03-31  3:30 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
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 [this message]
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=20150331032953.GA842@peff.net \
    --to=peff@peff.net \
    --cc=blees@dcon.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sbeller@google.com \
    --cc=tanoku@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.