packfile: fix memory leak in add_delta_base_cache()
commitbda959c4766d73ab435f26f2cc7c8c67b9443f5a
authorMatheus Tavares <matheus.bernardino@usp.br>
Tue, 29 Sep 2020 00:01:53 +0000 (28 21:01 -0300)
committerJunio C Hamano <gitster@pobox.com>
Tue, 29 Sep 2020 00:41:53 +0000 (28 17:41 -0700)
treed7ddc14cf2d77d2a9a467ce6e2c83dece7618fcb
parent74b052f8c269ef0b6f61a5ecf04a8568399345d9
packfile: fix memory leak in add_delta_base_cache()

When add_delta_base_cache() is called with a base that is already in the
cache, no operation is performed. But the check is done after allocating
space for a new entry, so we end up leaking memory on the early return.
In addition, the caller never free()'s the base as it expects the
function to take ownership of it. But the base is not released when we
skip insertion, so it also gets leaked. To fix these problems, move the
allocation of a new entry further down in add_delta_base_cache(), and
free() the base on early return.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
packfile.c