Thu, 15 May 2025 15:43:30 +0200
fix that testing allocator is counting free(NULL)
tests/util_allocator.c | file | annotate | diff | comparison | revisions |
--- a/tests/util_allocator.c Sun May 04 17:22:30 2025 +0200 +++ b/tests/util_allocator.c Thu May 15 15:43:30 2025 +0200 @@ -80,16 +80,18 @@ static void *cx_realloc_testing(void *d, void *mem, size_t n) { CxTestingAllocator *data = d; void *ptr = realloc(mem, n); - if (ptr == mem) { + if (mem != NULL && ptr == mem) { return ptr; } else { data->alloc_total++; if (ptr == NULL) { data->alloc_failed++; } else { - data->free_total++; - if (!cx_testing_allocator_untrack(data, mem)) { - data->free_failed++; + if (mem != NULL) { + data->free_total++; + if (!cx_testing_allocator_untrack(data, mem)) { + data->free_failed++; + } } cx_testing_allocator_track(data, ptr); } @@ -110,6 +112,7 @@ } static void cx_free_testing(void *d, void *mem) { + if (mem == NULL) return; CxTestingAllocator *data = d; data->free_total++; if (cx_testing_allocator_untrack(data, mem)) {