Re: [PATCH V2 5/6] pack-bitmap: fix a memleak
On Fri, Mar 27, 2015 at 6:32 PM, Stefan Beller <sbeller@google.com> wrote:
Show 65 quoted lines
> `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.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> diff --git a/pack-bitmap.c b/pack-bitmap.c
> index 365f9d9..34823e9 100644
> --- a/pack-bitmap.c
> +++ b/pack-bitmap.c
> @@ -213,7 +213,7 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
> {
> static const size_t MAX_XOR_OFFSET = 160;
>
> - uint32_t i;
> + uint32_t i, ret = 0;
> struct stored_bitmap **recent_bitmaps;
>
> recent_bitmaps = xcalloc(MAX_XOR_OFFSET, sizeof(struct stored_bitmap));
> @@ -232,24 +232,31 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
> sha1 = nth_packed_object_sha1(index->pack, commit_idx_pos);
>
> bitmap = read_bitmap_1(index);
> - if (!bitmap)
> - return -1;
> + if (!bitmap) {
> + ret = -1;
> + goto out;
> + }
>
> - 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;
> + }
>
> if (xor_offset > 0) {
> xor_bitmap = recent_bitmaps[(i - xor_offset) % MAX_XOR_OFFSET];
>
> - if (xor_bitmap == NULL)
> - return error("Invalid XOR offset in bitmap pack index");
> + if (xor_bitmap == NULL) {
> + ret = error("Invalid XOR offset in bitmap pack index");
> + goto out;
> + }
> }
>
> recent_bitmaps[i % MAX_XOR_OFFSET] = store_bitmap(
> index, bitmap, sha1, xor_bitmap, flags);
> }
> -
> - return 0;
> +out:
> + free(recent_bitmaps);
> + return ret;
> }
>
> static char *pack_bitmap_filename(struct packed_git *p)
> @@ -986,6 +993,8 @@ void test_bitmap_walk(struct rev_info *revs)
> fprintf(stderr, "OK!\n");
> else
> fprintf(stderr, "Mismatch!\n");
> +
> + free(result);This fix is not mentioned in the commit message.
Show 5 quoted lines
> }
>
> static int rebuild_bitmap(uint32_t *reposition,
> --
> 2.3.0.81.gc37f363