run-command tests: use "return", not "exit"

Change the "run-command" test helper to "return" instead of calling
"exit", see 338abb0f04 (builtins + test helpers: use return instead
of exit() in cmd_*, 2021-06-08)

Because we'd previously gotten past the SANITIZE=leak check by using
exit() here we need to move to "goto cleanup" pattern.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason
2022-10-12 23:02:22 +02:00
committed by Junio C Hamano
parent 7dd5762d9f
commit 910e2b372f

View File

@ -381,13 +381,14 @@ int cmd__run_command(int argc, const char **argv)
{ {
struct child_process proc = CHILD_PROCESS_INIT; struct child_process proc = CHILD_PROCESS_INIT;
int jobs; int jobs;
int ret;
if (argc > 1 && !strcmp(argv[1], "testsuite")) if (argc > 1 && !strcmp(argv[1], "testsuite"))
exit(testsuite(argc - 1, argv + 1)); return testsuite(argc - 1, argv + 1);
if (!strcmp(argv[1], "inherited-handle")) if (!strcmp(argv[1], "inherited-handle"))
exit(inherit_handle(argv[0])); return inherit_handle(argv[0]);
if (!strcmp(argv[1], "inherited-handle-child")) if (!strcmp(argv[1], "inherited-handle-child"))
exit(inherit_handle_child()); return inherit_handle_child();
if (argc >= 2 && !strcmp(argv[1], "quote-stress-test")) if (argc >= 2 && !strcmp(argv[1], "quote-stress-test"))
return !!quote_stress_test(argc - 1, argv + 1); return !!quote_stress_test(argc - 1, argv + 1);
@ -404,18 +405,24 @@ int cmd__run_command(int argc, const char **argv)
argv += 2; argv += 2;
argc -= 2; argc -= 2;
} }
if (argc < 3) if (argc < 3) {
return 1; ret = 1;
goto cleanup;
}
strvec_pushv(&proc.args, (const char **)argv + 2); strvec_pushv(&proc.args, (const char **)argv + 2);
if (!strcmp(argv[1], "start-command-ENOENT")) { if (!strcmp(argv[1], "start-command-ENOENT")) {
if (start_command(&proc) < 0 && errno == ENOENT) if (start_command(&proc) < 0 && errno == ENOENT) {
return 0; ret = 0;
goto cleanup;
}
fprintf(stderr, "FAIL %s\n", argv[1]); fprintf(stderr, "FAIL %s\n", argv[1]);
return 1; return 1;
} }
if (!strcmp(argv[1], "run-command")) if (!strcmp(argv[1], "run-command")) {
exit(run_command(&proc)); ret = run_command(&proc);
goto cleanup;
}
if (!strcmp(argv[1], "--ungroup")) { if (!strcmp(argv[1], "--ungroup")) {
argv += 1; argv += 1;
@ -436,8 +443,12 @@ int cmd__run_command(int argc, const char **argv)
run_processes_parallel(jobs, no_job, NULL, task_finished, run_processes_parallel(jobs, no_job, NULL, task_finished,
&proc); &proc);
} else { } else {
ret = 1;
fprintf(stderr, "check usage\n"); fprintf(stderr, "check usage\n");
return 1; goto cleanup;
} }
exit(0); ret = 0;
cleanup:
child_process_clear(&proc);
return ret;
} }