Re: [PATCH 11/26] cat-file: fix memory leak
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 27, 2017, 06:10 UTC
- Message-ID
- <xmqqo9vimldf.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <a1381df96c940f1edf5b7fb0c49abfc7b12b72fa.1493237937.git.johannes.schindelin@gmx.de>
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
Show 18 quoted lines
> Discovered by Coverity.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> builtin/cat-file.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/builtin/cat-file.c b/builtin/cat-file.c
> index 1890d7a6390..9af863e7915 100644
> --- a/builtin/cat-file.c
> +++ b/builtin/cat-file.c
> @@ -165,6 +165,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
> die("git cat-file %s: bad file", obj_name);
>
> write_or_die(1, buf, size);
> + free(buf);
> return 0;
> }This is a border-line "Meh". Just like we do not free resources immediately before calling die(), we can leave this as-is as the only thing that happens after this is a return from cmd_cat_file() back to main() that exits.
The patch is not wrong per-se, so I've applied it anyway, though.
Thanks.