use special valgrind option to detect memory leaks
I am hoping that this task fails now
This commit is contained in:
+1
-2
@@ -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
|
// Using the return a keyword in the statement following this macro will cause
|
||||||
// a guaranteed memory leak.
|
// a guaranteed memory leak.
|
||||||
#define with_borrow(NAME) \
|
#define with_borrow(NAME) \
|
||||||
borrow_allocator_t UNIQUE = borrow_allocator_create(); \
|
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 (allocator_t NAME = borrow_allocator_interface(&UNIQUE); !UNIQUE.head; UNIQUE.head = (borrow_allocator_reset(&UNIQUE), (linked_allocation_node_t*) 1)) \
|
|
||||||
for (int UNIQUE = 0; UNIQUE < 1; UNIQUE++)
|
for (int UNIQUE = 0; UNIQUE < 1; UNIQUE++)
|
||||||
|
|
||||||
#ifdef ALLOCATOR_IMPLEMENTATION
|
#ifdef ALLOCATOR_IMPLEMENTATION
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ test:
|
|||||||
echo "Compiling all test files into $(TESTBIN)..."; \
|
echo "Compiling all test files into $(TESTBIN)..."; \
|
||||||
$(CC) $(CFLAGS) _allocator_impl.c $$files -o $(TESTBIN) $(LDFLAGS) || exit 1; \
|
$(CC) $(CFLAGS) _allocator_impl.c $$files -o $(TESTBIN) $(LDFLAGS) || exit 1; \
|
||||||
echo "Running tests..."; \
|
echo "Running tests..."; \
|
||||||
valgrind $(TESTBIN); \
|
valgrind --trace-children=yes $(TESTBIN); \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,15 @@ Test(borrow_allocator, test) {
|
|||||||
borrow_allocator_reset(&balloc);
|
borrow_allocator_reset(&balloc);
|
||||||
cr_assert_eq(0, borrow_allocator_count_allocations(&balloc));
|
cr_assert_eq(0, borrow_allocator_count_allocations(&balloc));
|
||||||
borrow_allocator_assert_all_freed(&balloc);
|
borrow_allocator_assert_all_freed(&balloc);
|
||||||
|
void *foobar = malloc(1000);
|
||||||
|
(void)foobar;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define IS_SIZE 900
|
#define IS_SIZE 900
|
||||||
Test(borrow_allocator, with) {
|
Test(borrow_allocator, with) {
|
||||||
with_borrow(foo) {
|
with_borrow(foo) {
|
||||||
|
with_borrow(bar) {
|
||||||
|
}
|
||||||
int *is = allocator_alloc(foo, sizeof(int) * IS_SIZE);
|
int *is = allocator_alloc(foo, sizeof(int) * IS_SIZE);
|
||||||
for (int i = 0; i < IS_SIZE; i++) is[i] = i;
|
for (int i = 0; i < IS_SIZE; i++) is[i] = i;
|
||||||
is = allocator_alloc(foo, sizeof(int) * IS_SIZE);
|
is = allocator_alloc(foo, sizeof(int) * IS_SIZE);
|
||||||
|
|||||||
Reference in New Issue
Block a user