Merge pull request #2811 from ethomson/remote_leak remote: plug leak
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
diff --git a/src/remote.c b/src/remote.c
index c79e58a..5ba7735 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -139,7 +139,7 @@ static int canonicalize_url(git_buf *out, const char *in)
static int create_internal(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch)
{
git_remote *remote;
- git_config *config;
+ git_config *config = NULL;
git_buf canonical_url = GIT_BUF_INIT, fetchbuf = GIT_BUF_INIT;
int error = -1;
@@ -183,12 +183,12 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_NONE;
*out = remote;
- git_buf_free(&fetchbuf);
- git_buf_free(&canonical_url);
- return 0;
+ error = 0;
on_error:
- git_remote_free(remote);
+ if (error)
+ git_remote_free(remote);
+
git_config_free(config);
git_buf_free(&fetchbuf);
git_buf_free(&canonical_url);
diff --git a/tests/submodule/init.c b/tests/submodule/init.c
index d07bc9a..6d4c75c 100644
--- a/tests/submodule/init.c
+++ b/tests/submodule/init.c
@@ -41,6 +41,7 @@ void test_submodule_init__absolute_url(void)
git_buf_free(&absolute_url);
git_config_free(cfg);
+ git_submodule_free(sm);
}
void test_submodule_init__relative_url(void)
@@ -70,6 +71,7 @@ void test_submodule_init__relative_url(void)
git_buf_free(&absolute_url);
git_config_free(cfg);
+ git_submodule_free(sm);
}
void test_submodule_init__relative_url_detached_head(void)
@@ -107,5 +109,7 @@ void test_submodule_init__relative_url_detached_head(void)
git_buf_free(&absolute_url);
git_config_free(cfg);
-
+ git_commit_free(head_commit);
+ git_reference_free(head_ref);
+ git_submodule_free(sm);
}