feat: changed usage of leaks for our own leak detector by reference counting
This commit is contained in:
@@ -5,3 +5,4 @@ Arena Allocator of the NI-C system
|
||||
## Dependencies
|
||||
|
||||
- [ni-const](https://codecave.studiosi.es/studiosi/ni-const) constants library of the NI-C system
|
||||
- [ni-leakdetector](https://codecave.studiosi.es/studiosi/ni-leakdetector) leak detector of the NI-C system
|
||||
7
makefile
7
makefile
@@ -15,12 +15,7 @@ test: bin/test
|
||||
bin/test/niarena_test_alloc_arena
|
||||
bin/test/niarena_test_alloc_buffer
|
||||
|
||||
leaks: bin/test
|
||||
leaks --atExit -- bin/test/niarena_test
|
||||
leaks --atExit -- bin/test/niarena_test_alloc_arena
|
||||
leaks --atExit -- bin/test/niarena_test_alloc_buffer
|
||||
|
||||
.PHONY: clean format test leaks
|
||||
.PHONY: clean format test
|
||||
|
||||
bin/test: test/niarena_test.c
|
||||
mkdir -p bin/test
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#define N_INTS_TEST 4
|
||||
#define NIARENA_ARENA_SIZE (N_INTS_TEST * sizeof(int))
|
||||
#define NIARENA_IMPLEMENTATION
|
||||
#define NILEAKDETECTOR_VERBOSE true
|
||||
|
||||
#include "../../ni-leakdetector/nileakdetector.h"
|
||||
#include "../niarena.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
@@ -14,6 +16,7 @@ test_arena_new()
|
||||
assert(arena->offset == 0);
|
||||
assert(arena->capacity == (N_INTS_TEST * sizeof(int)));
|
||||
niarena_delete(arena);
|
||||
nileakdetector_print_summary();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -40,6 +43,7 @@ test_arena_allocations()
|
||||
}
|
||||
|
||||
niarena_delete(arena);
|
||||
nileakdetector_print_summary();
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
bad_malloc(size_t sz)
|
||||
@@ -14,6 +16,7 @@ mock_free(void *p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
#define NIARENA_FREE(p) mock_free(p)
|
||||
|
||||
#define N_INTS_TEST 4
|
||||
@@ -21,8 +24,6 @@ mock_free(void *p)
|
||||
#define NIARENA_IMPLEMENTATION
|
||||
|
||||
#include "../niarena.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
niarena_test_malloc_fail_arena()
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#define NILEAKDETECTOR_VERBOSE true
|
||||
#include "../../ni-leakdetector/nileakdetector.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -35,6 +38,7 @@ niarena_test_malloc_fail_buffer()
|
||||
assert(arena == NULL);
|
||||
const char *err = niarena_get_error();
|
||||
assert(strcmp(err, "niarena_new: out of memory allocating buffer") == 0);
|
||||
nileakdetector_print_summary();
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user