Merge pull request #3437 from libgit2/cmn/plug-sm submodule: plug a few leaks
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
diff --git a/src/submodule.c b/src/submodule.c
index 1d73dc2..998ef91 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;