From c31beaaec196c26990139e3fc4f89f996d7b86e9 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sun, 19 Dec 2021 02:43:36 +0100 Subject: Add new plist_mem_free() function Thanks to @azerg for bringing this to my attention. Instead of having multiple (internally identical) plist_*_free() functions, this commit introduces a single plist_mem_free() that can be used to free the memory allocated by plist_to_xml(), plist_to_bin(), plist_get_key_val(), plist_get_string_val(), and plist_get_data_val(). Note: This commit REMOVES plist_to_bin_free() and plist_to_xml_free(). --- src/bplist.c | 5 ----- src/plist.c | 8 ++++++++ src/xplist.c | 5 ----- 3 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/bplist.c b/src/bplist.c index 455c34b..a41ce1a 100644 --- a/src/bplist.c +++ b/src/bplist.c @@ -1374,8 +1374,3 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) bplist_buff->data = NULL; // make sure we don't free the output buffer byte_array_free(bplist_buff); } - -PLIST_API void plist_to_bin_free(char *plist_bin) -{ - free(plist_bin); -} diff --git a/src/plist.c b/src/plist.c index d0e6c77..386b04e 100644 --- a/src/plist.c +++ b/src/plist.c @@ -382,6 +382,14 @@ PLIST_API void plist_free(plist_t plist) } } +PLIST_API void plist_mem_free(void* ptr) +{ + if (ptr) + { + free(ptr); + } +} + static plist_t plist_copy_node(node_t *node) { plist_type node_type = PLIST_NONE; diff --git a/src/xplist.c b/src/xplist.c index 2eaba55..c45a984 100644 --- a/src/xplist.c +++ b/src/xplist.c @@ -530,11 +530,6 @@ PLIST_API void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length) str_buf_free(outbuf); } -PLIST_API void plist_to_xml_free(char *plist_xml) -{ - free(plist_xml); -} - struct _parse_ctx { const char *pos; const char *end; -- cgit v1.1-32-gdbae