summaryrefslogtreecommitdiff
path: root/src/config_parse.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-11-12 13:59:47 +0000
committerPatrick Steinhardt <ps@pks.im>2018-06-22 09:44:52 +0200
commite51e29e84c16f7a5d9079c2dc645301a54fdb172 (patch)
tree746aa411b937d268da2660874bed723fecdfe858 /src/config_parse.c
parente212011b9872c52f6205d3a30b10f753c3108918 (diff)
downloadlibgit2-e51e29e84c16f7a5d9079c2dc645301a54fdb172.tar.gz
config_parse: have `git_config_parse` own entry value and name
The function `git_config_parse` uses several callbacks to pass data along to the caller as it parses the file. One design shortcoming here is that strings passed to those callbacks are expected to be freed by them, which is really confusing. Fix the issue by changing memory ownership here. Instead of expecting the `on_variable` callbacks to free memory for `git_config_parse`, just do it inside of `git_config_parse`. While this obviously requires a bit more memory allocation churn due to having to copy both name and value at some places, this shouldn't be too much of a burden.
Diffstat (limited to 'src/config_parse.c')
-rw-r--r--src/config_parse.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/config_parse.c b/src/config_parse.c
index 66ac43237..ffbc466e7 100644
--- a/src/config_parse.c
+++ b/src/config_parse.c
@@ -463,7 +463,7 @@ int git_config_parse(
void *data)
{
git_parse_ctx *ctx;
- char *current_section = NULL, *var_name, *var_value;
+ char *current_section = NULL, *var_name = NULL, *var_value = NULL;
int result = 0;
ctx = &parser->ctx;
@@ -508,7 +508,10 @@ int git_config_parse(
default: /* assume variable declaration */
if ((result = parse_variable(parser, &var_name, &var_value)) == 0 && on_variable) {
result = on_variable(parser, current_section, var_name, var_value, line_start, line_len, data);
+ git__free(var_name);
+ git__free(var_value);
}
+
break;
}