submodule--helper: fix obscure leak in module_add()
Fix an obscure leak in module_add(), if the "git add" command we were piping to failed we'd fail to strbuf_release(&sb). This fixes a leak introduced ina6226fd772
(submodule--helper: convert the bulk of cmd_add() to C, 2021-08-10). In fixing it move to a "goto cleanup" pattern, and since we need to introduce a "ret" variable to do that let's also get rid of the intermediate "exit_code" variable. The initialization to "-1" ina6226fd772
has always been redundant, we'd only use the "exit_code" value after assigning the return value of pipe_command() to it. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
4c81ee9669
commit
4e83605d38
@ -3293,6 +3293,8 @@ static int module_add(int argc, const char **argv, const char *prefix)
|
|||||||
N_("git submodule add [<options>] [--] <repository> [<path>]"),
|
N_("git submodule add [<options>] [--] <repository> [<path>]"),
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
struct strbuf sb = STRBUF_INIT;
|
||||||
|
int ret = 1;
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix, options, usage, 0);
|
argc = parse_options(argc, argv, prefix, options, usage, 0);
|
||||||
|
|
||||||
@ -3342,21 +3344,17 @@ static int module_add(int argc, const char **argv, const char *prefix)
|
|||||||
die_on_repo_without_commits(add_data.sm_path);
|
die_on_repo_without_commits(add_data.sm_path);
|
||||||
|
|
||||||
if (!force) {
|
if (!force) {
|
||||||
int exit_code = -1;
|
|
||||||
struct strbuf sb = STRBUF_INIT;
|
|
||||||
struct child_process cp = CHILD_PROCESS_INIT;
|
struct child_process cp = CHILD_PROCESS_INIT;
|
||||||
|
|
||||||
cp.git_cmd = 1;
|
cp.git_cmd = 1;
|
||||||
cp.no_stdout = 1;
|
cp.no_stdout = 1;
|
||||||
strvec_pushl(&cp.args, "add", "--dry-run", "--ignore-missing",
|
strvec_pushl(&cp.args, "add", "--dry-run", "--ignore-missing",
|
||||||
"--no-warn-embedded-repo", add_data.sm_path, NULL);
|
"--no-warn-embedded-repo", add_data.sm_path, NULL);
|
||||||
if ((exit_code = pipe_command(&cp, NULL, 0, NULL, 0, &sb, 0))) {
|
if ((ret = pipe_command(&cp, NULL, 0, NULL, 0, &sb, 0))) {
|
||||||
strbuf_complete_line(&sb);
|
strbuf_complete_line(&sb);
|
||||||
fputs(sb.buf, stderr);
|
fputs(sb.buf, stderr);
|
||||||
free(add_data.sm_path);
|
goto cleanup;
|
||||||
return exit_code;
|
|
||||||
}
|
}
|
||||||
strbuf_release(&sb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!add_data.sm_name)
|
if(!add_data.sm_name)
|
||||||
@ -3371,15 +3369,17 @@ static int module_add(int argc, const char **argv, const char *prefix)
|
|||||||
add_data.progress = !!progress;
|
add_data.progress = !!progress;
|
||||||
add_data.dissociate = !!dissociate;
|
add_data.dissociate = !!dissociate;
|
||||||
|
|
||||||
if (add_submodule(&add_data)) {
|
if (add_submodule(&add_data))
|
||||||
free(add_data.sm_path);
|
goto cleanup;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
configure_added_submodule(&add_data);
|
configure_added_submodule(&add_data);
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
free(add_data.sm_path);
|
free(add_data.sm_path);
|
||||||
free(to_free);
|
free(to_free);
|
||||||
|
strbuf_release(&sb);
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SUPPORT_SUPER_PREFIX (1<<0)
|
#define SUPPORT_SUPER_PREFIX (1<<0)
|
||||||
|
Loading…
Reference in New Issue
Block a user