diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2017-05-04 15:58:35 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-05-08 12:18:20 +0900 |
commit | 7c565a6b2d8bf7fe989c85dc75df7fabc8113f40 (patch) | |
tree | 3ae91cd1d45ef0893c24ef63f02de3c0fbbc27af | |
parent | line-log: avoid memory leak (diff) | |
download | tgif-7c565a6b2d8bf7fe989c85dc75df7fabc8113f40.tar.xz |
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>
-rw-r--r-- | shallow.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -473,11 +473,15 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1, struct commit_list *head = NULL; int bitmap_nr = (info->nr_bits + 31) / 32; size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr); - uint32_t *tmp = xmalloc(bitmap_size); /* to be freed before return */ - uint32_t *bitmap = paint_alloc(info); struct commit *c = lookup_commit_reference_gently(sha1, 1); + uint32_t *tmp; /* to be freed before return */ + uint32_t *bitmap; + if (!c) return; + + tmp = xmalloc(bitmap_size); + bitmap = paint_alloc(info); memset(bitmap, 0, bitmap_size); bitmap[id / 32] |= (1U << (id % 32)); commit_list_insert(c, &head); |