From: Phillip Wood Date: Thu, 4 Oct 2018 10:07:43 +0000 (+0100) Subject: diff --color-moved-ws: fix a memory leak X-Git-Tag: v2.20.0-rc0~153^2~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/fe4516d103e69e74513be33f78768ac43acf3daa diff --color-moved-ws: fix a memory leak Don't duplicate the indentation string if we're not going to use it. This was found with asan. Signed-off-by: Phillip Wood Reviewed-by: Stefan Beller Signed-off-by: Junio C Hamano --- diff --git a/diff.c b/diff.c index 6f12212134..38f26091f3 100644 --- a/diff.c +++ b/diff.c @@ -811,10 +811,13 @@ static int compute_ws_delta(const struct emitted_diff_symbol *a, const struct emitted_diff_symbol *shorter = a->len > b->len ? b : a; int d = longer->len - shorter->len; + if (strncmp(longer->line + d, shorter->line, shorter->len)) + return 0; + out->string = xmemdupz(longer->line, d); out->current_longer = (a == longer); - return !strncmp(longer->line + d, shorter->line, shorter->len); + return 1; } static int cmp_in_block_with_wsd(const struct diff_options *o,