Skip to content

Commit 6073b3b

Browse files
pks-tgitster
authored andcommitted
config: clarify memory ownership in git_config_pathname()
The out parameter of `git_config_pathname()` 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f962ffc commit 6073b3b

18 files changed

+44
-39
lines changed

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ static int git_blame_config(const char *var, const char *value,
718718
return 0;
719719
}
720720
if (!strcmp(var, "blame.ignorerevsfile")) {
721-
const char *str;
721+
char *str;
722722
int ret;
723723

724724
ret = git_config_pathname(&str, var, value);

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static enum {
107107
} commit_style;
108108

109109
static const char *logfile, *force_author;
110-
static const char *template_file;
110+
static char *template_file;
111111
/*
112112
* The _message variables are commit names from which to take
113113
* the commit message and/or authorship.

builtin/config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static int format_config(struct strbuf *buf, const char *key_,
277277
else
278278
strbuf_addstr(buf, v ? "true" : "false");
279279
} else if (type == TYPE_PATH) {
280-
const char *v;
280+
char *v;
281281
if (git_config_pathname(&v, key_, value_) < 0)
282282
return -1;
283283
strbuf_addstr(buf, v);

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ static int do_signoff;
957957
static enum auto_base_setting auto_base;
958958
static char *from;
959959
static const char *signature = git_version_string;
960-
static const char *signature_file;
960+
static char *signature_file;
961961
static enum cover_setting config_cover_letter;
962962
static const char *config_output_directory;
963963
static enum cover_from_description cover_from_description_mode = COVER_FROM_MESSAGE;

builtin/receive-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ static int receive_pack_config(const char *var, const char *value,
168168
}
169169

170170
if (strcmp(var, "receive.fsck.skiplist") == 0) {
171-
const char *path;
171+
char *path;
172172

173173
if (git_config_pathname(&path, var, value))
174174
return 1;
175175
strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
176176
fsck_msg_types.len ? ',' : '=', path);
177-
free((char *)path);
177+
free(path);
178178
return 0;
179179
}
180180

config.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ int git_config_string(const char **dest, const char *var, const char *value)
13461346
return 0;
13471347
}
13481348

1349-
int git_config_pathname(const char **dest, const char *var, const char *value)
1349+
int git_config_pathname(char **dest, const char *var, const char *value)
13501350
{
13511351
if (!value)
13521352
return config_error_nonbool(var);
@@ -1597,7 +1597,7 @@ static int git_default_core_config(const char *var, const char *value,
15971597
return git_config_string(&askpass_program, var, value);
15981598

15991599
if (!strcmp(var, "core.excludesfile")) {
1600-
free((char *)excludes_file);
1600+
free(excludes_file);
16011601
return git_config_pathname(&excludes_file, var, value);
16021602
}
16031603

@@ -2494,7 +2494,7 @@ int git_configset_get_maybe_bool(struct config_set *set, const char *key, int *d
24942494
return 1;
24952495
}
24962496

2497-
int git_configset_get_pathname(struct config_set *set, const char *key, const char **dest)
2497+
int git_configset_get_pathname(struct config_set *set, const char *key, char **dest)
24982498
{
24992499
const char *value;
25002500
if (!git_configset_get_value(set, key, &value, NULL))
@@ -2639,7 +2639,7 @@ int repo_config_get_maybe_bool(struct repository *repo,
26392639
}
26402640

26412641
int repo_config_get_pathname(struct repository *repo,
2642-
const char *key, const char **dest)
2642+
const char *key, char **dest)
26432643
{
26442644
int ret;
26452645
git_config_check_init(repo);
@@ -2738,7 +2738,7 @@ int git_config_get_maybe_bool(const char *key, int *dest)
27382738
return repo_config_get_maybe_bool(the_repository, key, dest);
27392739
}
27402740

2741-
int git_config_get_pathname(const char *key, const char **dest)
2741+
int git_config_get_pathname(const char *key, char **dest)
27422742
{
27432743
return repo_config_get_pathname(the_repository, key, dest);
27442744
}

config.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ int git_config_string(const char **, const char *, const char *);
286286
* Similar to `git_config_string`, but expands `~` or `~user` into the
287287
* user's home directory when found at the beginning of the path.
288288
*/
289-
int git_config_pathname(const char **, const char *, const char *);
289+
int git_config_pathname(char **, const char *, const char *);
290290

291291
int git_config_expiry_date(timestamp_t *, const char *, const char *);
292292
int git_config_color(char *, const char *, const char *);
@@ -541,7 +541,7 @@ int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned lon
541541
int git_configset_get_bool(struct config_set *cs, const char *key, int *dest);
542542
int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest);
543543
int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
544-
int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest);
544+
int git_configset_get_pathname(struct config_set *cs, const char *key, char **dest);
545545

546546
/* Functions for reading a repository's config */
547547
struct repository;
@@ -577,7 +577,7 @@ int repo_config_get_bool_or_int(struct repository *repo,
577577
int repo_config_get_maybe_bool(struct repository *repo,
578578
const char *key, int *dest);
579579
int repo_config_get_pathname(struct repository *repo,
580-
const char *key, const char **dest);
580+
const char *key, char **dest);
581581

582582
/*
583583
* Functions for reading protected config. By definition, protected
@@ -687,7 +687,7 @@ int git_config_get_maybe_bool(const char *key, int *dest);
687687
* Similar to `git_config_get_string`, but expands `~` or `~user` into
688688
* the user's home directory when found at the beginning of the path.
689689
*/
690-
int git_config_get_pathname(const char *key, const char **dest);
690+
int git_config_get_pathname(const char *key, char **dest);
691691

692692
int git_config_get_index_threads(int *dest);
693693
int git_config_get_split_index(void);

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int diff_context_default = 3;
5858
static int diff_interhunk_context_default;
5959
static const char *diff_word_regex_cfg;
6060
static const char *external_diff_cmd_cfg;
61-
static const char *diff_order_file_cfg;
61+
static char *diff_order_file_cfg;
6262
int diff_auto_refresh_index = 1;
6363
static int diff_mnemonic_prefix;
6464
static int diff_no_prefix;

environment.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ const char *git_commit_encoding;
4646
const char *git_log_output_encoding;
4747
char *apply_default_whitespace;
4848
char *apply_default_ignorewhitespace;
49-
const char *git_attributes_file;
50-
const char *git_hooks_path;
49+
char *git_attributes_file;
50+
char *git_hooks_path;
5151
int zlib_compression_level = Z_BEST_SPEED;
5252
int pack_compression_level = Z_DEFAULT_COMPRESSION;
5353
int fsync_object_files = -1;
@@ -60,7 +60,7 @@ size_t delta_base_cache_limit = 96 * 1024 * 1024;
6060
unsigned long big_file_threshold = 512 * 1024 * 1024;
6161
const char *editor_program;
6262
const char *askpass_program;
63-
const char *excludes_file;
63+
char *excludes_file;
6464
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
6565
enum eol core_eol = EOL_UNSET;
6666
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;

environment.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ extern int warn_ambiguous_refs;
131131
extern int warn_on_object_refname_ambiguity;
132132
extern char *apply_default_whitespace;
133133
extern char *apply_default_ignorewhitespace;
134-
extern const char *git_attributes_file;
135-
extern const char *git_hooks_path;
134+
extern char *git_attributes_file;
135+
extern char *git_hooks_path;
136136
extern int zlib_compression_level;
137137
extern int pack_compression_level;
138138
extern size_t packed_git_window_size;
@@ -229,7 +229,7 @@ extern const char *git_log_output_encoding;
229229

230230
extern const char *editor_program;
231231
extern const char *askpass_program;
232-
extern const char *excludes_file;
232+
extern char *excludes_file;
233233

234234
/*
235235
* Should we print an ellipsis after an abbreviated SHA-1 value

0 commit comments

Comments
 (0)