fix that testing allocator is counting free(NULL)

Thu, 15 May 2025 15:43:30 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 15 May 2025 15:43:30 +0200
changeset 1317
eeb2fc3850e2
parent 1316
c41538edfcef
child 1318
12fa1d37fe48

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)) {

mercurial