Skip to content

Commit b6f8870

Browse files
committed
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.
1 parent 2d1f667 commit b6f8870

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

src/config_file.c

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,20 @@ static int config_error_readonly(void)
8282
return -1;
8383
}
8484

85-
static void cvar_free(config_entry_list *var)
85+
static void config_entry_list_free(config_entry_list *list)
8686
{
87-
if (var == NULL)
88-
return;
87+
config_entry_list *next;
88+
89+
while (list != NULL) {
90+
next = list->next;
91+
92+
git__free((char*) list->entry->name);
93+
git__free((char *) list->entry->value);
94+
git__free(list->entry);
95+
git__free(list);
8996

90-
git__free((char*)var->entry->name);
91-
git__free((char *)var->entry->value);
92-
git__free(var->entry);
93-
git__free(var);
97+
list = next;
98+
};
9499
}
95100

96101
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)
144149
return error;
145150
}
146151

147-
static void free_vars(git_strmap *values)
148-
{
149-
config_entry_list *var = NULL;
150-
151-
if (values == NULL)
152-
return;
153-
154-
git_strmap_foreach_value(values, var,
155-
while (var != NULL) {
156-
config_entry_list *next = var->next;
157-
cvar_free(var);
158-
var = next;
159-
});
160-
161-
git_strmap_free(values);
162-
}
163-
164152
static void refcounted_strmap_free(refcounted_strmap *map)
165153
{
154+
config_entry_list *list = NULL;
155+
166156
if (!map)
167157
return;
168158

169159
if (git_atomic_dec(&map->refcount) != 0)
170160
return;
171161

172-
free_vars(map->values);
162+
git_strmap_foreach_value(map->values, list, config_entry_list_free(list));
163+
git_strmap_free(map->values);
173164
git__free(map);
174165
}
175166

0 commit comments

Comments
 (0)