path: root/remote.c
diff options
authorJeff King <>2018-11-22 17:31:09 (GMT)
committerJunio C Hamano <>2019-01-12 02:35:53 (GMT)
commit54e8c1121574fca675438ac0bbd7f6a375b92520 (patch)
treed238f873bb98bce797b2950105d9cae82a39ed2b /remote.c
parent98cdfbb84ad2ed6a2eb43dafa357a70a4b0a0fad (diff)
remote: check config validity before creating rewrite struct
When parsing, we call make_rewrite() and only then check to make sure the config value is a string (and return an error if it isn't). This isn't quite a leak, because the struct we allocate is part of a global array, but it does leave a funny half-finished struct. In practice, it doesn't make much difference because we exit soon after due to the config error anyway. But let's flip the order here to avoid leaving a trap for somebody in the future. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'remote.c')
1 files changed, 2 insertions, 2 deletions
diff --git a/remote.c b/remote.c
index 7f6277a..571dab6 100644
--- a/remote.c
+++ b/remote.c
@@ -335,14 +335,14 @@ static int handle_config(const char *key, const char *value, void *cb)
if (!name)
return 0;
if (!strcmp(subkey, "insteadof")) {
- rewrite = make_rewrite(&rewrites, name, namelen);
if (!value)
return config_error_nonbool(key);
+ rewrite = make_rewrite(&rewrites, name, namelen);
add_instead_of(rewrite, xstrdup(value));
} else if (!strcmp(subkey, "pushinsteadof")) {
- rewrite = make_rewrite(&rewrites_push, name, namelen);
if (!value)
return config_error_nonbool(key);
+ rewrite = make_rewrite(&rewrites_push, name, namelen);
add_instead_of(rewrite, xstrdup(value));