git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH V2 5/6] pack-bitmap: fix a memleak

From
Jeff King <peff@peff.net>
Date
Mar 31, 2015, 03:29 UTC
Message-ID
<20150331032953.GA842@peff.net>
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...
Show 6 quoted lines
> -		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
Previous: Eric SunshineNext: Stefan Beller
Message 10 of 14 in “Memory leaks once again”
  1. 0/6 Memory leaks once againStefan Beller, Mar 27, 2015
  2. 1/6 shallow: fix a memleakStefan Beller, Mar 27, 2015
  3. Eric SunshineMar 27, 2015
  4. 2/6 line-log.c: fix a memleakStefan Beller, Mar 27, 2015
  5. 3/6 line-log.c: fix a memleakStefan Beller, Mar 27, 2015
  6. 4/6 wt-status.c: fix a memleakStefan Beller, Mar 27, 2015
  7. Eric SunshineMar 27, 2015
  8. 5/6 pack-bitmap: fix a memleakStefan Beller, Mar 27, 2015
  9. Eric SunshineMar 27, 2015
  10. Jeff KingMar 31, 2015
  11. 6/6 WIP/RFC/entry.c: fix a memleakStefan Beller, Mar 27, 2015
  12. Eric SunshineMar 27, 2015
  13. Eric SunshineMar 28, 2015
  14. John KeepingMar 28, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.