feat: changed usage of leaks for our own leak detector by reference counting

This commit is contained in:
2026-01-11 11:08:33 +02:00
parent 8bc3fa085e
commit fb89b45fef
5 changed files with 14 additions and 9 deletions

View File

@@ -5,3 +5,4 @@ Arena Allocator of the NI-C system
## Dependencies ## Dependencies
- [ni-const](https://codecave.studiosi.es/studiosi/ni-const) constants library of the NI-C system - [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

View File

@@ -15,12 +15,7 @@ test: bin/test
bin/test/niarena_test_alloc_arena bin/test/niarena_test_alloc_arena
bin/test/niarena_test_alloc_buffer bin/test/niarena_test_alloc_buffer
leaks: bin/test .PHONY: clean format 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
bin/test: test/niarena_test.c bin/test: test/niarena_test.c
mkdir -p bin/test mkdir -p bin/test

View File

@@ -1,7 +1,9 @@
#define N_INTS_TEST 4 #define N_INTS_TEST 4
#define NIARENA_ARENA_SIZE (N_INTS_TEST * sizeof(int)) #define NIARENA_ARENA_SIZE (N_INTS_TEST * sizeof(int))
#define NIARENA_IMPLEMENTATION #define NIARENA_IMPLEMENTATION
#define NILEAKDETECTOR_VERBOSE true
#include "../../ni-leakdetector/nileakdetector.h"
#include "../niarena.h" #include "../niarena.h"
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
@@ -14,6 +16,7 @@ test_arena_new()
assert(arena->offset == 0); assert(arena->offset == 0);
assert(arena->capacity == (N_INTS_TEST * sizeof(int))); assert(arena->capacity == (N_INTS_TEST * sizeof(int)));
niarena_delete(arena); niarena_delete(arena);
nileakdetector_print_summary();
} }
void void
@@ -40,6 +43,7 @@ test_arena_allocations()
} }
niarena_delete(arena); niarena_delete(arena);
nileakdetector_print_summary();
} }
int int

View File

@@ -1,5 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <string.h>
void * void *
bad_malloc(size_t sz) bad_malloc(size_t sz)
@@ -14,6 +16,7 @@ mock_free(void *p)
{ {
free(p); free(p);
} }
#define NIARENA_FREE(p) mock_free(p) #define NIARENA_FREE(p) mock_free(p)
#define N_INTS_TEST 4 #define N_INTS_TEST 4
@@ -21,8 +24,6 @@ mock_free(void *p)
#define NIARENA_IMPLEMENTATION #define NIARENA_IMPLEMENTATION
#include "../niarena.h" #include "../niarena.h"
#include <assert.h>
#include <string.h>
void void
niarena_test_malloc_fail_arena() niarena_test_malloc_fail_arena()

View File

@@ -1,3 +1,6 @@
#define NILEAKDETECTOR_VERBOSE true
#include "../../ni-leakdetector/nileakdetector.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -35,6 +38,7 @@ niarena_test_malloc_fail_buffer()
assert(arena == NULL); assert(arena == NULL);
const char *err = niarena_get_error(); const char *err = niarena_get_error();
assert(strcmp(err, "niarena_new: out of memory allocating buffer") == 0); assert(strcmp(err, "niarena_new: out of memory allocating buffer") == 0);
nileakdetector_print_summary();
} }
int int