Free the config var hash contents in git_config_free Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/src/config.c b/src/config.c
index 22ba5f5..5c500c4 100644
--- a/src/config.c
+++ b/src/config.c
@@ -35,6 +35,15 @@
***********************/
static int config_parse(git_config *cfg_file);
static int parse_variable(git_config *cfg, const char *section_name, const char *line);
+void git_config_free(git_config *cfg);
+
+static void cvar_free(git_cvar *var)
+{
+ if(var->type == GIT_VAR_STR)
+ free(var->value.string);
+
+ free(var);
+}
uint32_t config_table_hash(const void *key, int hash_id)
{
@@ -101,10 +110,18 @@ int git_config_open(git_config **cfg_out, const char *path)
void git_config_free(git_config *cfg)
{
+ git_cvar *var;
+ const void *_unused;
+
if (cfg == NULL)
return;
free(cfg->file_path);
+
+ GIT_HASHTABLE_FOREACH(cfg->vars, _unused, var,
+ cvar_free(var);
+ );
+
git_hashtable_free(cfg->vars);
gitfo_free_buf(&cfg->reader.buffer);