diff options
| author | Mattias Andrée <m@maandree.se> | 2026-05-14 15:55:33 +0200 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-05-14 15:55:33 +0200 |
| commit | 4e6f25806e3c9fa4753ce959ef990167796acd32 (patch) | |
| tree | e641de9953f5b58afc1f36efe9c42a0d20254cd2 /libtest/libtest_fd_tracking.c | |
| parent | Fix libtest and add file descriptor leak detection (diff) | |
| download | librecrypt-4e6f25806e3c9fa4753ce959ef990167796acd32.tar.gz librecrypt-4e6f25806e3c9fa4753ce959ef990167796acd32.tar.bz2 librecrypt-4e6f25806e3c9fa4753ce959ef990167796acd32.tar.xz | |
Tests and fixes
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'libtest/libtest_fd_tracking.c')
| -rw-r--r-- | libtest/libtest_fd_tracking.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/libtest/libtest_fd_tracking.c b/libtest/libtest_fd_tracking.c index d3c766c..25cea8f 100644 --- a/libtest/libtest_fd_tracking.c +++ b/libtest/libtest_fd_tracking.c @@ -11,6 +11,9 @@ struct fd { static size_t nopened = 0u; static struct fd *opened = NULL; +static atomic_flag spinlock = ATOMIC_FLAG_INIT; +static int tracking_state = -1; + static int cmp_fd(const void *av, const void *bv) @@ -60,6 +63,14 @@ libtest_fd_tracking(int action) int accept_memleak = libtest_malloc_accept_leakage; size_t i, j; char *path; + int old_tracking_state; + + SPINLOCK(spinlock); + old_tracking_state = tracking_state; + tracking_state = action; + SPINUNLOCK(spinlock); + if (old_tracking_state == action) + return 1; /* so libtest doesn't complain about us not zeroing before freeing, * and so it will not report memory leaks in fprintf from our |
