Skip to content

Commit a77d6db

Browse files
peffgitster
authored andcommitted
git_config_parse_parameter: refactor cleanup code
We have several exits from the function, each of which has to do some cleanup. Let's consolidate these in an "out" label we can jump to. This doesn't save us much now, but it will help as we add more things that need cleanup. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c72ee44 commit a77d6db

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

config.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ int git_config_parse_parameter(const char *text,
205205
int git_config_from_parameters(config_fn_t fn, void *data)
206206
{
207207
const char *env = getenv(CONFIG_DATA_ENVIRONMENT);
208+
int ret = 0;
208209
char *envw;
209210
const char **argv = NULL;
210211
int nr = 0, alloc = 0;
@@ -216,21 +217,21 @@ int git_config_from_parameters(config_fn_t fn, void *data)
216217
envw = xstrdup(env);
217218

218219
if (sq_dequote_to_argv(envw, &argv, &nr, &alloc) < 0) {
219-
free(envw);
220-
return error("bogus format in " CONFIG_DATA_ENVIRONMENT);
220+
ret = error("bogus format in " CONFIG_DATA_ENVIRONMENT);
221+
goto out;
221222
}
222223

223224
for (i = 0; i < nr; i++) {
224225
if (git_config_parse_parameter(argv[i], fn, data) < 0) {
225-
free(argv);
226-
free(envw);
227-
return -1;
226+
ret = -1;
227+
goto out;
228228
}
229229
}
230230

231+
out:
231232
free(argv);
232233
free(envw);
233-
return 0;
234+
return ret;
234235
}
235236

236237
static int get_next_char(void)

0 commit comments

Comments
 (0)