From 814a26857808b397d9822600c72d77ae6bf1af9b Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 22 Feb 2025 22:12:01 +0100 Subject: [PATCH] Free previously allocated JSON array only if element exists in TOML file Signed-off-by: DL6ER --- src/config/toml_helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/config/toml_helper.c b/src/config/toml_helper.c index 8eed6f928..eaa28fe7f 100644 --- a/src/config/toml_helper.c +++ b/src/config/toml_helper.c @@ -730,13 +730,13 @@ void readTOMLvalue(struct conf_item *conf_item, const char* key, toml_table_t *t } case CONF_JSON_STRING_ARRAY: { - // Free previously allocated JSON array - cJSON_Delete(conf_item->v.json); - conf_item->v.json = cJSON_CreateArray(); - // Parse TOML array and generate a JSON array const toml_array_t *array = toml_array_in(toml, key); if(array != NULL) { + // Free previously allocated JSON array if element exists + cJSON_Delete(conf_item->v.json); + conf_item->v.json = cJSON_CreateArray(); + const unsigned int nelem = toml_array_nelem(array); for(unsigned int i = 0; i < nelem; i++) {