[PATCH 3/5] diff --color-moved-ws: fix a memory leak
- From
- Phillip Wood <phillip.wood@talktalk.net>
- Date
- Oct 2, 2018, 17:55 UTC
- Message-ID
- <20181002175514.31495-3-phillip.wood@talktalk.net>
- In-Reply-To
- <20181002175514.31495-1-phillip.wood@talktalk.net>
From: Phillip Wood <phillip.wood@dunelm.org.uk>
Don't duplicate the indentation string if we're not going to use it. This was found with asan.
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> --- diff.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/diff.c b/diff.c index 0096bdc339..efadd05c90 100644 --- a/diff.c +++ b/diff.c @@ -785,11 +785,15 @@ static int compute_ws_delta(const struct emitted_diff_symbol *a, const struct emitted_diff_symbol *longer = a->len > b->len ? a : b; const struct emitted_diff_symbol *shorter = a->len > b->len ? b : a; int d = longer->len - shorter->len; + int ret = !strncmp(longer->line + d, shorter->line, shorter->len); + + if (!ret) + return ret; out->string = xmemdupz(longer->line, d); out->current_longer = (a == longer); - return !strncmp(longer->line + d, shorter->line, shorter->len); + return ret; } static int cmp_in_block_with_wsd(const struct diff_options *o,
-- 2.19.0