Skip to content

Commit

Permalink
Free previously allocated JSON array only if element exists in TOML file
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Feb 22, 2025
1 parent 5852f7e commit 814a268
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/config/toml_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down

0 comments on commit 814a268

Please sign in to comment.