From ab8f2c669a2a0bb66d5473f83ecb47ad805a7078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 23 Sep 2015 15:09:19 +0200 Subject: [PATCH] submodule: plug a few leaks --- src/submodule.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/submodule.c b/src/submodule.c index 1d73dc24e..998ef91fd 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -170,7 +170,7 @@ static int name_from_path(git_buf *out, git_config *cfg, const char *path) git_buf_clear(out); git_buf_put(out, fdot + 1, ldot - fdot - 1); - return 0; + goto cleanup; } if (error == GIT_ITEROVER) { @@ -178,6 +178,8 @@ static int name_from_path(git_buf *out, git_config *cfg, const char *path) error = GIT_ENOTFOUND; } +cleanup: + git_config_iterator_free(iter); return error; } @@ -1701,7 +1703,7 @@ static int submodule_read_config(git_submodule *sm, git_config *cfg) GITERR_CHECK_ALLOC(sm->path); } } else if (error != GIT_ENOTFOUND) { - return error; + goto cleanup; } if ((error = get_value(&value, cfg, &key, sm->name, "url")) == 0) { @@ -1709,7 +1711,7 @@ static int submodule_read_config(git_submodule *sm, git_config *cfg) sm->url = git__strdup(value); GITERR_CHECK_ALLOC(sm->url); } else if (error != GIT_ENOTFOUND) { - return error; + goto cleanup; } if ((error = get_value(&value, cfg, &key, sm->name, "branch")) == 0) { @@ -1717,40 +1719,44 @@ static int submodule_read_config(git_submodule *sm, git_config *cfg) sm->branch = git__strdup(value); GITERR_CHECK_ALLOC(sm->branch); } else if (error != GIT_ENOTFOUND) { - return error; + goto cleanup; } if ((error = get_value(&value, cfg, &key, sm->name, "update")) == 0) { in_config = 1; if ((error = git_submodule_parse_update(&sm->update, value)) < 0) - return error; + goto cleanup; sm->update_default = sm->update; } else if (error != GIT_ENOTFOUND) { - return error; + goto cleanup; } if ((error = get_value(&value, cfg, &key, sm->name, "fetchRecurseSubmodules")) == 0) { in_config = 1; if ((error = git_submodule_parse_recurse(&sm->fetch_recurse, value)) < 0) - return error; + goto cleanup; sm->fetch_recurse_default = sm->fetch_recurse; } else if (error != GIT_ENOTFOUND) { - return error; + goto cleanup; } if ((error = get_value(&value, cfg, &key, sm->name, "ignore")) == 0) { in_config = 1; if ((error = git_submodule_parse_ignore(&sm->ignore, value)) < 0) - return error; + goto cleanup; sm->ignore_default = sm->ignore; } else if (error != GIT_ENOTFOUND) { - return error; + goto cleanup; } if (in_config) sm->flags |= GIT_SUBMODULE_STATUS_IN_CONFIG; - return 0; + error = 0; + +cleanup: + git_buf_free(&key); + return error; } static int submodule_load_each(const git_config_entry *entry, void *payload) @@ -1784,8 +1790,10 @@ static int submodule_load_each(const git_config_entry *entry, void *payload) * already inserted, we've already loaded it, so we skip. */ pos = git_strmap_lookup_index(map, name.ptr); - if (git_strmap_valid_index(map, pos)) - return 0; + if (git_strmap_valid_index(map, pos)) { + error = 0; + goto done; + } if ((error = submodule_alloc(&sm, data->repo, name.ptr)) < 0) goto done;