summaryrefslogtreecommitdiff
path: root/src/remote.c
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-05-07 10:04:50 +0200
committernulltoken <emeric.fermas@gmail.com>2012-05-08 10:05:09 +0200
commit2fb9d6de95b7ba430cb2fab0da754a8074fa0c43 (patch)
tree5bb6edee9a37a9aa9041b6506b63b063858dd966 /src/remote.c
parent8d89c8e9726bdb257ff3a54182f927d4ed30d439 (diff)
downloadlibgit2-2fb9d6de95b7ba430cb2fab0da754a8074fa0c43.tar.gz
remote: ensure the allocated remote is freed when an error occurs during its loading
Diffstat (limited to 'src/remote.c')
-rw-r--r--src/remote.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/remote.c b/src/remote.c
index 98c256929..a30841427 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -102,11 +102,15 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
remote->name = git__strdup(name);
GITERR_CHECK_ALLOC(remote->name);
- if (git_vector_init(&remote->refs, 32, NULL) < 0)
- return -1;
+ if (git_vector_init(&remote->refs, 32, NULL) < 0) {
+ error = -1;
+ goto cleanup;
+ }
- if (git_buf_printf(&buf, "remote.%s.url", name) < 0)
- return -1;
+ if (git_buf_printf(&buf, "remote.%s.url", name) < 0) {
+ error = -1;
+ goto cleanup;
+ }
if (git_config_get_string(config, git_buf_cstr(&buf), &val) < 0) {
error = -1;
@@ -118,8 +122,10 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
GITERR_CHECK_ALLOC(remote->url);
git_buf_clear(&buf);
- if (git_buf_printf(&buf, "remote.%s.fetch", name) < 0)
- return -1;
+ if (git_buf_printf(&buf, "remote.%s.fetch", name) < 0) {
+ error = -1;
+ goto cleanup;
+ }
error = parse_remote_refspec(config, &remote->fetch, git_buf_cstr(&buf));
if (error == GIT_ENOTFOUND)
@@ -131,8 +137,10 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
}
git_buf_clear(&buf);
- if (git_buf_printf(&buf, "remote.%s.push", name) < 0)
- return -1;
+ if (git_buf_printf(&buf, "remote.%s.push", name) < 0) {
+ error = -1;
+ goto cleanup;
+ }
error = parse_remote_refspec(config, &remote->push, git_buf_cstr(&buf));
if (error == GIT_ENOTFOUND)