builtin/rebase: do not assign default backend to non-constant field
The `struct rebase_options::default_backend` field is a non-constant string, but is being assigned a constant via `REBASE_OPTIONS_INIT`. Fix this by using `xstrdup()` to assign the variable and introduce a new function `rebase_options_release()` that releases memory held by the structure, including the newly-allocated variable. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
6d1f198f34
commit
25a47ffac0
@ -135,7 +135,7 @@ struct rebase_options {
|
|||||||
.type = REBASE_UNSPECIFIED, \
|
.type = REBASE_UNSPECIFIED, \
|
||||||
.empty = EMPTY_UNSPECIFIED, \
|
.empty = EMPTY_UNSPECIFIED, \
|
||||||
.keep_empty = 1, \
|
.keep_empty = 1, \
|
||||||
.default_backend = "merge", \
|
.default_backend = xstrdup("merge"), \
|
||||||
.flags = REBASE_NO_QUIET, \
|
.flags = REBASE_NO_QUIET, \
|
||||||
.git_am_opts = STRVEC_INIT, \
|
.git_am_opts = STRVEC_INIT, \
|
||||||
.exec = STRING_LIST_INIT_NODUP, \
|
.exec = STRING_LIST_INIT_NODUP, \
|
||||||
@ -151,6 +151,19 @@ struct rebase_options {
|
|||||||
.strategy_opts = STRING_LIST_INIT_NODUP,\
|
.strategy_opts = STRING_LIST_INIT_NODUP,\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void rebase_options_release(struct rebase_options *opts)
|
||||||
|
{
|
||||||
|
free(opts->default_backend);
|
||||||
|
free(opts->reflog_action);
|
||||||
|
free(opts->head_name);
|
||||||
|
strvec_clear(&opts->git_am_opts);
|
||||||
|
free(opts->gpg_sign_opt);
|
||||||
|
string_list_clear(&opts->exec, 0);
|
||||||
|
free(opts->strategy);
|
||||||
|
string_list_clear(&opts->strategy_opts, 0);
|
||||||
|
strbuf_release(&opts->git_format_patch_opt);
|
||||||
|
}
|
||||||
|
|
||||||
static struct replay_opts get_replay_opts(const struct rebase_options *opts)
|
static struct replay_opts get_replay_opts(const struct rebase_options *opts)
|
||||||
{
|
{
|
||||||
struct replay_opts replay = REPLAY_OPTS_INIT;
|
struct replay_opts replay = REPLAY_OPTS_INIT;
|
||||||
@ -796,6 +809,7 @@ static int rebase_config(const char *var, const char *value,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(var, "rebase.backend")) {
|
if (!strcmp(var, "rebase.backend")) {
|
||||||
|
FREE_AND_NULL(opts->default_backend);
|
||||||
return git_config_string(&opts->default_backend, var, value);
|
return git_config_string(&opts->default_backend, var, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1833,14 +1847,7 @@ run_rebase:
|
|||||||
cleanup:
|
cleanup:
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
strbuf_release(&revisions);
|
strbuf_release(&revisions);
|
||||||
free(options.reflog_action);
|
rebase_options_release(&options);
|
||||||
free(options.head_name);
|
|
||||||
strvec_clear(&options.git_am_opts);
|
|
||||||
free(options.gpg_sign_opt);
|
|
||||||
string_list_clear(&options.exec, 0);
|
|
||||||
free(options.strategy);
|
|
||||||
string_list_clear(&options.strategy_opts, 0);
|
|
||||||
strbuf_release(&options.git_format_patch_opt);
|
|
||||||
free(squash_onto_name);
|
free(squash_onto_name);
|
||||||
free(keep_base_onto_name);
|
free(keep_base_onto_name);
|
||||||
return !!ret;
|
return !!ret;
|
||||||
|
Reference in New Issue
Block a user