aboutsummaryrefslogtreecommitdiffstats
path: root/builtin
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-05-27 13:46:39 +0200
committerJunio C Hamano <gitster@pobox.com>2024-05-27 11:20:00 -0700
commit1b261c20ed28ad26ddbcd3dff94a248ac6866ac8 (patch)
tree2b035eeafac8bc875b83bc643a0bff20aedd53c3 /builtin
parentbuiltin/log: stop using globals for format config (diff)
downloadgit-1b261c20ed28ad26ddbcd3dff94a248ac6866ac8.tar.gz
git-1b261c20ed28ad26ddbcd3dff94a248ac6866ac8.zip
config: clarify memory ownership in `git_config_string()`
The out parameter of `git_config_string()` is a `const char **` even though we transfer ownership of memory to the caller. This is quite misleading and has led to many memory leaks all over the place. Adapt the parameter to instead be `char **`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/commit.c2
-rw-r--r--builtin/log.c12
-rw-r--r--builtin/merge.c4
-rw-r--r--builtin/rebase.c2
-rw-r--r--builtin/receive-pack.c2
-rw-r--r--builtin/repack.c8
6 files changed, 15 insertions, 15 deletions
diff --git a/builtin/commit.c b/builtin/commit.c
index 1cc88e92bf..f53e7e86ff 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -133,7 +133,7 @@ static struct strvec trailer_args = STRVEC_INIT;
* is specified explicitly.
*/
static enum commit_msg_cleanup_mode cleanup_mode;
-static const char *cleanup_arg;
+static char *cleanup_arg;
static enum commit_whence whence;
static int use_editor = 1, include_status = 1;
diff --git a/builtin/log.c b/builtin/log.c
index 890bf0c425..517d7982f1 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -582,11 +582,11 @@ static int git_log_config(const char *var, const char *value,
if (!strcmp(var, "format.pretty")) {
FREE_AND_NULL(cfg->fmt_pretty);
- return git_config_string((const char **) &cfg->fmt_pretty, var, value);
+ return git_config_string(&cfg->fmt_pretty, var, value);
}
if (!strcmp(var, "format.subjectprefix")) {
FREE_AND_NULL(cfg->fmt_patch_subject_prefix);
- return git_config_string((const char **) &cfg->fmt_patch_subject_prefix, var, value);
+ return git_config_string(&cfg->fmt_patch_subject_prefix, var, value);
}
if (!strcmp(var, "format.filenamemaxlength")) {
cfg->fmt_patch_name_max = git_config_int(var, value, ctx->kvi);
@@ -602,7 +602,7 @@ static int git_log_config(const char *var, const char *value,
}
if (!strcmp(var, "log.date")) {
FREE_AND_NULL(cfg->default_date_mode);
- return git_config_string((const char **) &cfg->default_date_mode, var, value);
+ return git_config_string(&cfg->default_date_mode, var, value);
}
if (!strcmp(var, "log.decorate")) {
cfg->decoration_style = parse_decoration_style(value);
@@ -1076,7 +1076,7 @@ static int git_format_config(const char *var, const char *value,
}
if (!strcmp(var, "format.suffix")) {
FREE_AND_NULL(cfg->fmt_patch_suffix);
- return git_config_string((const char **) &cfg->fmt_patch_suffix, var, value);
+ return git_config_string(&cfg->fmt_patch_suffix, var, value);
}
if (!strcmp(var, "format.to")) {
if (!value)
@@ -1133,7 +1133,7 @@ static int git_format_config(const char *var, const char *value,
}
if (!strcmp(var, "format.signature")) {
FREE_AND_NULL(cfg->signature);
- return git_config_string((const char **) &cfg->signature, var, value);
+ return git_config_string(&cfg->signature, var, value);
}
if (!strcmp(var, "format.signaturefile")) {
FREE_AND_NULL(cfg->signature_file);
@@ -1149,7 +1149,7 @@ static int git_format_config(const char *var, const char *value,
}
if (!strcmp(var, "format.outputdirectory")) {
FREE_AND_NULL(cfg->config_output_directory);
- return git_config_string((const char **) &cfg->config_output_directory, var, value);
+ return git_config_string(&cfg->config_output_directory, var, value);
}
if (!strcmp(var, "format.useautobase")) {
if (value && !strcasecmp(value, "whenAble")) {
diff --git a/builtin/merge.c b/builtin/merge.c
index e4bd65eeba..daed2d4e1e 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -100,7 +100,7 @@ static struct strategy all_strategy[] = {
{ "subtree", NO_FAST_FORWARD | NO_TRIVIAL },
};
-static const char *pull_twohead, *pull_octopus;
+static char *pull_twohead, *pull_octopus;
enum ff_type {
FF_NO,
@@ -110,7 +110,7 @@ enum ff_type {
static enum ff_type fast_forward = FF_ALLOW;
-static const char *cleanup_arg;
+static char *cleanup_arg;
static enum commit_msg_cleanup_mode cleanup_mode;
static int option_parse_message(const struct option *opt,
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 0466d9414a..14d4f0a5e6 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -83,7 +83,7 @@ static const char *action_names[] = {
struct rebase_options {
enum rebase_type type;
enum empty_type empty;
- const char *default_backend;
+ char *default_backend;
const char *state_dir;
struct commit *upstream;
const char *upstream_name;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 56228ad314..01c1f04ece 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -88,7 +88,7 @@ static struct strbuf push_cert = STRBUF_INIT;
static struct object_id push_cert_oid;
static struct signature_check sigcheck;
static const char *push_cert_nonce;
-static const char *cert_nonce_seed;
+static char *cert_nonce_seed;
static struct strvec hidden_refs = STRVEC_INIT;
static const char *NONCE_UNSOLICITED = "UNSOLICITED";
diff --git a/builtin/repack.c b/builtin/repack.c
index 43491a4cbf..e40dceaada 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -48,10 +48,10 @@ static const char incremental_bitmap_conflict_error[] = N_(
);
struct pack_objects_args {
- const char *window;
- const char *window_memory;
- const char *depth;
- const char *threads;
+ char *window;
+ char *window_memory;
+ char *depth;
+ char *threads;
unsigned long max_pack_size;
int no_reuse_delta;
int no_reuse_object;