summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2018-10-04 10:07:43 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-10-05 05:48:12 (GMT)
commitfe4516d103e69e74513be33f78768ac43acf3daa (patch)
tree617b37a74c95a17528b4a71f98f0848fc7fe93b1 /diff.c
parentcf074a9b0e589bad8e6b210ac1e3a4714463f7db (diff)
downloadgit-fe4516d103e69e74513be33f78768ac43acf3daa.zip
git-fe4516d103e69e74513be33f78768ac43acf3daa.tar.gz
git-fe4516d103e69e74513be33f78768ac43acf3daa.tar.bz2
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 <phillip.wood@dunelm.org.uk> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/diff.c b/diff.c
index 6f12212..38f2609 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,