diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-07-29 21:33:32 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-07-29 21:33:32 +0530 |
commit | 56d0a87cc7f4ca4985db93a719726345a073d20f (patch) | |
tree | 5180c021640bdf99f10cd495b95ea79e0c3a4739 /src | |
parent | c88c251b899ca0e0b3fe34217bdf2d6ce1b677be (diff) |
config: array_values must be wrapped
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 22 | ||||
-rw-r--r-- | src/main.c | 5 |
2 files changed, 12 insertions, 15 deletions
diff --git a/src/config.c b/src/config.c index 4576bfd..34bd7f5 100644 --- a/src/config.c +++ b/src/config.c @@ -13,7 +13,7 @@ config_parse(char *content) { list_t *keys = list_create(sizeof(ptr_wrapper_t)); list_t *values = list_create(sizeof(ptr_wrapper_t)); - list_t *array_values = list_create(sizeof(list_t)); + list_t *array_values = list_create(sizeof(ptr_wrapper_t)); char *buffer = strdup(content); /* For free() */ @@ -36,18 +36,13 @@ config_parse(char *content) value = strsep(&raw_array, DELIM_ARRAY); } - list_add(array_values, l); + list_add(array_values, wrap_ptr(l)); list_add(values, wrap_ptr(NULL)); - - free(l); } else { - list_t *l = list_create(sizeof(ptr_wrapper_t)); char *value = trim(strsep(&buffer, "\n")); - list_add(array_values, l); + list_add(array_values, wrap_ptr(NULL)); list_add(values, wrap_ptr(strdup(value))); - - list_delete(l); } key = trim(strsep(&buffer, DELIM)); @@ -76,12 +71,13 @@ config_delete(config_t *config) if (wrapper->ptr != NULL) free(wrapper->ptr); - list_t *l = list_get(config->array_values, i); - for (size_t y = 0; y < l->size; y++) { - wrapper = list_get(l, y); - - if (wrapper->ptr != NULL) + list_t *l = get_wrapped(list_get(config->array_values, i)); + if (l != NULL) { + for (size_t y = 0; y < l->size; y++) { + wrapper = list_get(l, y); free(wrapper->ptr); + } + list_delete(l); } } @@ -119,8 +119,9 @@ main(int argc, char **argv) free(assets_directory); config_t *config = config_fetch_and_parse(CONFIG_FILE); - list_t *resources = list_find_corresponding_value_from_ptr_wrapper( - config->keys, config->array_values, "resources"); + list_t *resources + = get_wrapped(list_find_corresponding_value_from_ptr_wrapper( + config->keys, config->array_values, "resources")); if (resources == NULL) { printf("Could not find resources in config.cfg\n"); |