Re: [PATCH V2 1/6] shallow: fix a memleak
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Mar 27, 2015, 23:01 UTC
- Message-ID
- <CAPig+cTpVwKG+6uK0HCyPUt0qKc7R6qWnLgVr8C9kodW4j2krg@mail.gmail.com>
- In-Reply-To
- <1427495569-10863-2-git-send-email-sbeller@google.com>
On Fri, Mar 27, 2015 at 6:32 PM, Stefan Beller <sbeller@google.com> wrote:
Show 12 quoted lines
> Signed-off-by: Stefan Beller <sbeller@google.com> > --- > diff --git a/shallow.c b/shallow.c > index d8bf40a..f8b0458 100644 > --- a/shallow.c > +++ b/shallow.c > @@ -416,7 +416,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1, > uint32_t *bitmap = paint_alloc(info); > struct commit *c = lookup_commit_reference_gently(sha1, 1); > if (!c) > - return; > + goto out;
Rather than slapping on a band-aid, a cleaner fix would be to move the allocation of 'tmp' below this conditional since 'tmp' is never used before the point of this early return.
Perhaps also move allocation of 'bitmap' below the early return (if you find that it's safe to do so).
Show 11 quoted lines
> memset(bitmap, 0, bitmap_size); > bitmap[id / 32] |= (1 << (id % 32)); > commit_list_insert(c, &head); > @@ -471,7 +471,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1, > if (o && o->type == OBJ_COMMIT) > o->flags &= ~SEEN; > } > - > +out: > free(tmp); > }