Skip to content

Commit fe4516d

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf074a9 commit fe4516d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

diff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,13 @@ static int compute_ws_delta(const struct emitted_diff_symbol *a,
811811
const struct emitted_diff_symbol *shorter = a->len > b->len ? b : a;
812812
int d = longer->len - shorter->len;
813813

814+
if (strncmp(longer->line + d, shorter->line, shorter->len))
815+
return 0;
816+
814817
out->string = xmemdupz(longer->line, d);
815818
out->current_longer = (a == longer);
816819

817-
return !strncmp(longer->line + d, shorter->line, shorter->len);
820+
return 1;
818821
}
819822

820823
static int cmp_in_block_with_wsd(const struct diff_options *o,

0 commit comments

Comments
 (0)