diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2017-05-01 19:34:04 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2017-05-01 22:55:12 +0100 |
commit | 4dbcf0e673b1761e536b9a5f385a771287f06232 (patch) | |
tree | 3f6666dfc02e5f82e41558892dd86fb01923cc05 | |
parent | be343b88c724491bcb945cafec9f95370eb1088f (diff) | |
download | libgit2-4dbcf0e673b1761e536b9a5f385a771287f06232.tar.gz |
remote: free the config snapshot
This reverts commit 5552237 and frees the snapshot properly.
-rw-r--r-- | src/remote.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/remote.c b/src/remote.c index d090fda61..bd8b3cfbc 100644 --- a/src/remote.c +++ b/src/remote.c @@ -192,7 +192,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 = NULL; + git_config *config_ro = NULL, *config_rw; git_buf canonical_url = GIT_BUF_INIT; git_buf var = GIT_BUF_INIT; int error = -1; @@ -200,7 +200,7 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n /* name is optional */ assert(out && repo && url); - if ((error = git_repository_config__weakptr(&config, repo)) < 0) + if ((error = git_repository_config_snapshot(&config_ro, repo)) < 0) return error; remote = git__calloc(1, sizeof(git_remote)); @@ -212,7 +212,8 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n (error = canonicalize_url(&canonical_url, url)) < 0) goto on_error; - remote->url = apply_insteadof(repo->_config, canonical_url.ptr, GIT_DIRECTION_FETCH); + remote->url = apply_insteadof(config_ro, canonical_url.ptr, GIT_DIRECTION_FETCH); + GITERR_CHECK_ALLOC(remote->url); if (name != NULL) { remote->name = git__strdup(name); @@ -221,7 +222,8 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n if ((error = git_buf_printf(&var, CONFIG_URL_FMT, name)) < 0) goto on_error; - if ((error = git_config_set_string(config, var.ptr, canonical_url.ptr)) < 0) + if ((error = git_repository_config__weakptr(&config_rw, repo)) < 0 || + (error = git_config_set_string(config_rw, var.ptr, canonical_url.ptr)) < 0) goto on_error; } @@ -233,10 +235,7 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n if (name && (error = write_add_refspec(repo, name, fetch, true)) < 0) goto on_error; - if ((error = git_repository_config_snapshot(&config, repo)) < 0) - goto on_error; - - if ((error = lookup_remote_prune_config(remote, config, name)) < 0) + if ((error = lookup_remote_prune_config(remote, config_ro, name)) < 0) goto on_error; /* Move the data over to where the matching functions can find them */ @@ -260,6 +259,7 @@ on_error: if (error) git_remote_free(remote); + git_config_free(config_ro); git_buf_free(&canonical_url); git_buf_free(&var); return error; |