Skip to content

Commit 637799b

Browse files
carenasgitster
authored andcommitted
tree-diff: fix leak when not HAVE_ALLOCA_H
b8ba412 (tree-diff: avoid alloca for large allocations, 2016-06-07) adds a way to route some bigger allocations out of the stack and free them through the addition of two conveniently named macros, but leaves the calls to free the xalloca part, which could be also in the heap, if the system doesn't HAVE_ALLOCA_H (ex: macOS and other BSD). Add the missing free call, xalloca_free(), which is a noop if we allocated memory in the stack frame, but a real free() if we allocated in the heap instead, and while at it, change the expression to match in both macros for ease of readability. This avoids a leak reported by LSAN while running t0000 but that wouldn't fail the test (which is fixed in the next patch): SUMMARY: LeakSanitizer: 1034 byte(s) leaked in 15 allocation(s). Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 225bc32 commit 637799b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tree-diff.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
ALLOC_ARRAY((x), nr); \
2222
} while(0)
2323
#define FAST_ARRAY_FREE(x, nr) do { \
24-
if ((nr) > 2) \
24+
if ((nr) <= 2) \
25+
xalloca_free((x)); \
26+
else \
2527
free((x)); \
2628
} while(0)
2729

0 commit comments

Comments
 (0)