diff options
author | David Robillard <d@drobilla.net> | 2021-01-16 14:45:36 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-01-16 14:45:36 +0100 |
commit | ce1e5cc0ee32d7b66b311b61bf38d9eefc522e7c (patch) | |
tree | 39356b6fae838c4ac7300a76480a978c437276f2 | |
parent | 08991af7b742a62a64ecb429662659a5a0a6ebc6 (diff) | |
download | zix-ce1e5cc0ee32d7b66b311b61bf38d9eefc522e7c.tar.gz zix-ce1e5cc0ee32d7b66b311b61bf38d9eefc522e7c.tar.bz2 zix-ce1e5cc0ee32d7b66b311b61bf38d9eefc522e7c.zip |
Allow all free functions to be called on null
-rw-r--r-- | src/ring.c | 6 | ||||
-rw-r--r-- | src/strindex.c | 10 | ||||
-rw-r--r-- | test/ring_test.c | 2 | ||||
-rw-r--r-- | test/strindex_test.c | 2 |
4 files changed, 14 insertions, 6 deletions
@@ -80,8 +80,10 @@ zix_ring_new(uint32_t size) void zix_ring_free(ZixRing* ring) { - free(ring->buf); - free(ring); + if (ring) { + free(ring->buf); + free(ring); + } } void diff --git a/src/strindex.c b/src/strindex.c index 6443a59..9a6d952 100644 --- a/src/strindex.c +++ b/src/strindex.c @@ -82,10 +82,12 @@ zix_strindex_free_rec(ZixStrindexNode* n) void zix_strindex_free(ZixStrindex* strindex) { - zix_strindex_free_rec(strindex->root); - free(strindex->s); - free(strindex->root); - free(strindex); + if (strindex) { + zix_strindex_free_rec(strindex->root); + free(strindex->s); + free(strindex->root); + free(strindex); + } } static inline int diff --git a/test/ring_test.c b/test/ring_test.c index d4d2d38..24163fe 100644 --- a/test/ring_test.c +++ b/test/ring_test.c @@ -129,6 +129,8 @@ main(int argc, char** argv) n_writes = (unsigned)atoi(argv[2]); } + zix_ring_free(NULL); + printf("Testing %u writes of %d ints to a %u int ring...\n", n_writes, MSG_SIZE, diff --git a/test/strindex_test.c b/test/strindex_test.c index 42d3c66..3cdfb25 100644 --- a/test/strindex_test.c +++ b/test/strindex_test.c @@ -37,6 +37,8 @@ test_fail(const char* fmt, ...) int main(void) { + zix_strindex_free(NULL); + const char* str = "BANANA"; const size_t str_len = strlen(str); ZixStrindex* strindex = zix_strindex_new(str); |