summaryrefslogtreecommitdiff
path: root/src/remote.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-12-21 15:31:03 +0000
committerCarlos Martín Nieto <cmn@dwim.me>2015-03-03 18:35:12 +0100
commit9a97f49e3aa15edc479fc590f4b28fc44c155c40 (patch)
treeb85de2d396b9d0d408f688212c0cdc74347ea7b3 /src/remote.c
parent76f034180aee96fcc1fffd5267ccbc6ada68482a (diff)
downloadlibgit2-9a97f49e3aa15edc479fc590f4b28fc44c155c40.tar.gz
config: borrow refcounted referencescmn/config-borrow-entry
This changes the get_entry() method to return a refcounted version of the config entry, which you have to free when you're done. This allows us to avoid freeing the memory in which the entry is stored on a refresh, which may happen at any time for a live config. For this reason, get_string() has been forbidden on live configs and a new function get_string_buf() has been added, which stores the string in a git_buf which the user then owns. The functions which parse the string value takea advantage of the borrowing to parse safely and then release the entry.
Diffstat (limited to 'src/remote.c')
-rw-r--r--src/remote.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/remote.c b/src/remote.c
index bc6d8a2c4..4924bf83a 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -52,7 +52,7 @@ static int add_refspec(git_remote *remote, const char *string, bool is_fetch)
static int download_tags_value(git_remote *remote, git_config *cfg)
{
- const git_config_entry *ce;
+ git_config_entry *ce;
git_buf buf = GIT_BUF_INIT;
int error;
@@ -70,6 +70,7 @@ static int download_tags_value(git_remote *remote, git_config *cfg)
remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
}
+ git_config_entry_free(ce);
return error;
}
@@ -548,7 +549,7 @@ int git_remote_save(const git_remote *remote)
git_config *cfg;
const char *tagopt = NULL;
git_buf buf = GIT_BUF_INIT;
- const git_config_entry *existing;
+ git_config_entry *existing = NULL;
assert(remote);
@@ -618,6 +619,7 @@ int git_remote_save(const git_remote *remote)
cfg, git_buf_cstr(&buf), tagopt, true, false);
cleanup:
+ git_config_entry_free(existing);
git_buf_free(&buf);
return error;
}
@@ -753,7 +755,7 @@ int git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote
int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_url)
{
git_config *cfg;
- const git_config_entry *ce;
+ git_config_entry *ce = NULL;
const char *val = NULL;
int error;
@@ -805,6 +807,7 @@ found:
*proxy_url = git__strdup(val);
GITERR_CHECK_ALLOC(*proxy_url);
}
+ git_config_entry_free(ce);
return 0;
}