use special valgrind option to detect memory leaks

I am hoping that this task fails now
This commit is contained in:
2025-10-11 03:18:34 +02:00
parent 86d5110b0b
commit 20cac1737e
3 changed files with 6 additions and 3 deletions
+1 -2
View File
@@ -93,8 +93,7 @@ allocator_t borrow_allocator_interface(borrow_allocator_t *this);
// Using the return a keyword in the statement following this macro will cause
// a guaranteed memory leak.
#define with_borrow(NAME) \
borrow_allocator_t UNIQUE = borrow_allocator_create(); \
for (allocator_t NAME = borrow_allocator_interface(&UNIQUE); !UNIQUE.head; UNIQUE.head = (borrow_allocator_reset(&UNIQUE), (linked_allocation_node_t*) 1)) \
for (allocator_t NAME = borrow_allocator_interface(&borrow_allocator_create()); !((borrow_allocator_t*)NAME.this)->head; ((borrow_allocator_t*)NAME.this)->head = (borrow_allocator_reset(((borrow_allocator_t*)NAME.this)), (linked_allocation_node_t*) 1)) \
for (int UNIQUE = 0; UNIQUE < 1; UNIQUE++)
#ifdef ALLOCATOR_IMPLEMENTATION
+1 -1
View File
@@ -16,7 +16,7 @@ test:
echo "Compiling all test files into $(TESTBIN)..."; \
$(CC) $(CFLAGS) _allocator_impl.c $$files -o $(TESTBIN) $(LDFLAGS) || exit 1; \
echo "Running tests..."; \
valgrind $(TESTBIN); \
valgrind --trace-children=yes $(TESTBIN); \
fi
+4
View File
@@ -11,11 +11,15 @@ Test(borrow_allocator, test) {
borrow_allocator_reset(&balloc);
cr_assert_eq(0, borrow_allocator_count_allocations(&balloc));
borrow_allocator_assert_all_freed(&balloc);
void *foobar = malloc(1000);
(void)foobar;
}
#define IS_SIZE 900
Test(borrow_allocator, with) {
with_borrow(foo) {
with_borrow(bar) {
}
int *is = allocator_alloc(foo, sizeof(int) * IS_SIZE);
for (int i = 0; i < IS_SIZE; i++) is[i] = i;
is = allocator_alloc(foo, sizeof(int) * IS_SIZE);