From ce1e5cc0ee32d7b66b311b61bf38d9eefc522e7c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 16 Jan 2021 14:45:36 +0100 Subject: Allow all free functions to be called on null --- src/ring.c | 6 ++++-- src/strindex.c | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ring.c b/src/ring.c index 6e26ebc..4a4692f 100644 --- a/src/ring.c +++ b/src/ring.c @@ -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 -- cgit v1.2.1