cmocka: Allow test_free() to deal with NULL pointers.
authorAndreas Schneider <asn@cryptomilk.org>
Fri, 6 Feb 2015 10:51:22 +0000 (11:51 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Sun, 8 Feb 2015 08:41:14 +0000 (09:41 +0100)
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
src/cmocka.c

index fe5faad..bac2ae5 100644 (file)
@@ -1516,8 +1516,12 @@ void* _test_calloc(const size_t number_of_elements, const size_t size,
 void _test_free(void* const ptr, const char* file, const int line) {
     unsigned int i;
     char *block = discard_const_p(char, ptr);
-
     MallocBlockInfo *block_info;
+
+    if (ptr == NULL) {
+        return;
+    }
+
     _assert_true(cast_ptr_to_largest_integral_type(ptr), "ptr", file, line);
     block_info = (MallocBlockInfo*)(block - (MALLOC_GUARD_SIZE +
                                                sizeof(*block_info)));