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>

Jeff King committed May 18, 2016 at 18:39 UTC a77d6db69b2cbd16e98763f33ceaa76ff5ca2c54
1 file changed +7 -6
config.c
+7 -6
@@ -205,6 +205,7 @@ int git_config_parse_parameter(const char *text,
205 int git_config_from_parameters(config_fn_t fn, void *data)
206 {
207 const char *env = getenv(CONFIG_DATA_ENVIRONMENT);
208 + int ret = 0;
209 char *envw;
210 const char **argv = NULL;
211 int nr = 0, alloc = 0;
@@ -216,21 +217,21 @@ int git_config_from_parameters(config_fn_t fn, void *data)
217 envw = xstrdup(env);
218
219 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;
222 }
223
224 for (i = 0; i < nr; i++) {
225 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;
228 }
229 }
230
231 +out:
232 free(argv);
233 free(envw);
233 - return 0;
234 + return ret;
235 }
236
237 static int get_next_char(void)