Commit b6f88706 by Patrick Steinhardt

config_file: refactor freeing of config entry lists

The interface for freeing config list entries is more tangled than
required. Instead of calling `cvar_free` for every list entry in
`free_vars`, we now just provide a function `config_entry_list_free`.
This function will iterate through all list entries and free the
associated configuration entry as well as the list entry itself.
parent 2d1f6676
......@@ -82,15 +82,20 @@ static int config_error_readonly(void)
return -1;
}
static void cvar_free(config_entry_list *var)
static void config_entry_list_free(config_entry_list *list)
{
if (var == NULL)
return;
config_entry_list *next;
while (list != NULL) {
next = list->next;
git__free((char*) list->entry->name);
git__free((char *) list->entry->value);
git__free(list->entry);
git__free(list);
git__free((char*)var->entry->name);
git__free((char *)var->entry->value);
git__free(var->entry);
git__free(var);
list = next;
};
}
int git_config_file_normalize_section(char *start, char *end)
......@@ -144,32 +149,18 @@ static int append_entry(git_strmap *values, git_config_entry *entry)
return error;
}
static void free_vars(git_strmap *values)
{
config_entry_list *var = NULL;
if (values == NULL)
return;
git_strmap_foreach_value(values, var,
while (var != NULL) {
config_entry_list *next = var->next;
cvar_free(var);
var = next;
});
git_strmap_free(values);
}
static void refcounted_strmap_free(refcounted_strmap *map)
{
config_entry_list *list = NULL;
if (!map)
return;
if (git_atomic_dec(&map->refcount) != 0)
return;
free_vars(map->values);
git_strmap_foreach_value(map->values, list, config_entry_list_free(list));
git_strmap_free(map->values);
git__free(map);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment