shallow: avoid memory leak
Reported by Coverity. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
May 4, 2017 at 15:58 UTC
7c565a6b2d8bf7fe989c85dc75df7fabc8113f40
1 file changed
+6
-2
shallow.c
+6
-2
@@ -473,11 +473,15 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
473
struct commit_list *head = NULL;
474
int bitmap_nr = (info->nr_bits + 31) / 32;
475
size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);
476
- uint32_t *tmp = xmalloc(bitmap_size); /* to be freed before return */
477
- uint32_t *bitmap = paint_alloc(info);
476
struct commit *c = lookup_commit_reference_gently(sha1, 1);
477
+ uint32_t *tmp; /* to be freed before return */
478
+ uint32_t *bitmap;
479
+
480
if (!c)
481
return;
482
+
483
+ tmp = xmalloc(bitmap_size);
484
+ bitmap = paint_alloc(info);
485
memset(bitmap, 0, bitmap_size);
486
bitmap[id / 32] |= (1U << (id % 32));
487
commit_list_insert(c, &head);