git/t/unit-tests
Johannes Schindelin d02c37c3e6 t-reftable-basics: allow for `malloc` to be `#define`d
As indicated by the `#undef malloc` line in `reftable/basics.h`, it is
quite common to use allocators other than the default one by defining
`malloc` constants and friends.

This pattern is used e.g. in Git for Windows, which uses the powerful
and performant `mimalloc` allocator.

Furthermore, in `reftable/basics.c` this `#undef malloc` is
_specifically_ disabled by virtue of defining the
`REFTABLE_ALLOW_BANNED_ALLOCATORS` constant before including
`reftable/basic.h`, to ensure that such a custom allocator is also used
in the reftable code.

However, in 8db127d43f (reftable: avoid leaks on realloc error,
2024-12-28) and in 2cca185e85 (reftable: fix allocation count on
realloc error, 2024-12-28), `reftable_set_alloc()` function calls were
introduced that pass `malloc`, `realloc` and `free` function pointers as
parameters _after_ `reftable/basics.h` ensured that they were no longer
`#define`d. This would override the custom allocator and re-set it to
the default allocator provided by, say, libc or MSVCRT.

This causes problems because those calls happen after the initial
allocator has already been used to initialize an array, which is
subsequently resized using the overridden default `realloc()` allocator.

You cannot mix and match allocators like that, which leads to a
`STATUS_HEAP_CORRUPTION` (C0000374) on Windows, and when running this
unit test through shell and/or `prove` (which only support 7-bit status
codes), it surfaces as exit code 127.

It is actually unnecessary to use those function pointers to
`malloc`/`realloc`/`free`, though: The `reftable` code goes out of its
way to fall back to the initial allocator when passing `NULL` parameters
instead. So let's do that instead of causing heap corruptions.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Acked-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-01-08 09:41:52 -08:00
..
clar t/unit-tests: update clar to 206accb 2024-10-21 16:53:07 -04:00
.gitignore Makefile: wire up the clar unit testing framework 2024-09-04 08:41:37 -07:00
generate-clar-decls.sh t/unit-tests: rename clar-based unit tests to have a common prefix 2024-12-13 06:48:46 -08:00
generate-clar-suites.sh t/unit-tests: convert "clar-generate.awk" into a shell script 2024-11-18 09:59:25 +09:00
lib-oid.c t: port helper/test-oid-array.c to unit-tests/t-oid-array.c 2024-09-01 20:43:38 -07:00
lib-oid.h t: port helper/test-oid-array.c to unit-tests/t-oid-array.c 2024-09-01 20:43:38 -07:00
lib-reftable.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
lib-reftable.h reftable/system: stop depending on "hash.h" 2024-11-19 12:23:10 +09:00
t-example-decorate.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
t-hash.c unit-tests: ignore unused argc/argv 2024-08-17 09:46:12 -07:00
t-hashmap.c t-hashmap: stop calling setup() for t_intern() test 2024-08-20 08:33:18 -07:00
t-mem-pool.c unit-tests: ignore unused argc/argv 2024-08-17 09:46:12 -07:00
t-oid-array.c t: port helper/test-oid-array.c to unit-tests/t-oid-array.c 2024-09-01 20:43:38 -07:00
t-oidmap.c t: migrate helper/test-oidmap.c to unit-tests/t-oidmap.c 2024-07-03 09:12:14 -07:00
t-oidtree.c t/: migrate helper/test-oidtree.c to unit-tests/t-oidtree.c 2024-06-12 13:33:20 -07:00
t-prio-queue.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
t-reftable-basics.c t-reftable-basics: allow for `malloc` to be `#define`d 2025-01-08 09:41:52 -08:00
t-reftable-block.c reftable/system: provide thin wrapper for lockfile subsystem 2024-11-19 12:23:11 +09:00
t-reftable-merged.c t-reftable-merged: handle realloc errors 2024-12-28 08:00:45 -08:00
t-reftable-pq.c reftable/system: provide thin wrapper for lockfile subsystem 2024-11-19 12:23:11 +09:00
t-reftable-reader.c reftable/system: stop depending on "hash.h" 2024-11-19 12:23:10 +09:00
t-reftable-readwrite.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
t-reftable-record.c reftable/system: stop depending on "hash.h" 2024-11-19 12:23:10 +09:00
t-reftable-stack.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
t-reftable-tree.c reftable/tree: handle allocation failures 2024-10-02 07:53:55 -07:00
t-strbuf.c unit-tests: ignore unused argc/argv 2024-08-17 09:46:12 -07:00
t-strcmp-offset.c unit-tests: ignore unused argc/argv 2024-08-17 09:46:12 -07:00
t-trailer.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
t-urlmatch-normalization.c t: migrate t0110-urlmatch-normalization to the new framework 2024-08-20 10:08:28 -07:00
test-lib.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
test-lib.h Merge branch 'rs/unit-tests-test-run' 2024-08-19 11:07:36 -07:00
u-ctype.c t/unit-tests: rename clar-based unit tests to have a common prefix 2024-12-13 06:48:46 -08:00
u-strvec.c Merge branch 'ps/ci-meson' 2024-12-23 09:32:25 -08:00
unit-test.c t: introduce compatibility options to clar-based tests 2024-12-13 06:48:47 -08:00
unit-test.h t/unit-tests: convert ctype tests to use clar 2024-09-04 08:41:37 -07:00