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

Change the "run-command" test helper to "return" instead of calling "exit", see 338abb0f045 (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>

Ævar Arnfjörð Bjarmason committed Oct 12, 2022 at 23:02 UTC 910e2b372f215263a79ae1d849274d2a212c16e2
1 file changed +22 -11
t/helper/test-run-command.c
+22 -11
@@ -381,13 +381,14 @@ int cmd__run_command(int argc, const char **argv)
381 {
382 struct child_process proc = CHILD_PROCESS_INIT;
383 int jobs;
384 + int ret;
385
386 if (argc > 1 && !strcmp(argv[1], "testsuite"))
386 - exit(testsuite(argc - 1, argv + 1));
387 + return testsuite(argc - 1, argv + 1);
388 if (!strcmp(argv[1], "inherited-handle"))
388 - exit(inherit_handle(argv[0]));
389 + return inherit_handle(argv[0]);
390 if (!strcmp(argv[1], "inherited-handle-child"))
390 - exit(inherit_handle_child());
391 + return inherit_handle_child();
392
393 if (argc >= 2 && !strcmp(argv[1], "quote-stress-test"))
394 return !!quote_stress_test(argc - 1, argv + 1);
@@ -404,18 +405,24 @@ int cmd__run_command(int argc, const char **argv)
405 argv += 2;
406 argc -= 2;
407 }
407 - if (argc < 3)
408 - return 1;
408 + if (argc < 3) {
409 + ret = 1;
410 + goto cleanup;
411 + }
412 strvec_pushv(&proc.args, (const char **)argv + 2);
413
414 if (!strcmp(argv[1], "start-command-ENOENT")) {
412 - if (start_command(&proc) < 0 && errno == ENOENT)
413 - return 0;
415 + if (start_command(&proc) < 0 && errno == ENOENT) {
416 + ret = 0;
417 + goto cleanup;
418 + }
419 fprintf(stderr, "FAIL %s\n", argv[1]);
420 return 1;
421 }
417 - if (!strcmp(argv[1], "run-command"))
418 - exit(run_command(&proc));
422 + if (!strcmp(argv[1], "run-command")) {
423 + ret = run_command(&proc);
424 + goto cleanup;
425 + }
426
427 if (!strcmp(argv[1], "--ungroup")) {
428 argv += 1;
@@ -436,8 +443,12 @@ int cmd__run_command(int argc, const char **argv)
443 run_processes_parallel(jobs, no_job, NULL, task_finished,
444 &proc);
445 } else {
446 + ret = 1;
447 fprintf(stderr, "check usage\n");
440 - return 1;
448 + goto cleanup;
449 }
442 - exit(0);
450 + ret = 0;
451 +cleanup:
452 + child_process_clear(&proc);
453 + return ret;
454 }