Skip to content

Commit cf79265

Browse files
committed
Merge branch 'ps/leakfixes'
Leakfixes. * ps/leakfixes: builtin/mv: fix leaks for submodule gitfile paths builtin/mv: refactor to use `struct strvec` builtin/mv duplicate string list memory builtin/mv: refactor `add_slash()` to always return allocated strings strvec: add functions to replace and remove strings submodule: fix leaking memory for submodule entries commit-reach: fix memory leak in `ahead_behind()` builtin/credential: clear credential before exit config: plug various memory leaks config: clarify memory ownership in `git_config_string()` builtin/log: stop using globals for format config builtin/log: stop using globals for log config convert: refactor code to clarify ownership of check_roundtrip_encoding diff: refactor code to clarify memory ownership of prefixes config: clarify memory ownership in `git_config_pathname()` http: refactor code to clarify memory ownership checkout: clarify memory ownership in `unique_tracking_name()` strbuf: fix leak when `appendwholeline()` fails with EOF transport-helper: fix leaking helper name
2 parents 7b0defb + ebdbefa commit cf79265

File tree

97 files changed

+1138
-585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1138
-585
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,7 @@ UNIT_TEST_PROGRAMS += t-mem-pool
13381338
UNIT_TEST_PROGRAMS += t-prio-queue
13391339
UNIT_TEST_PROGRAMS += t-strbuf
13401340
UNIT_TEST_PROGRAMS += t-strcmp-offset
1341+
UNIT_TEST_PROGRAMS += t-strvec
13411342
UNIT_TEST_PROGRAMS += t-trailer
13421343
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
13431344
UNIT_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(UNIT_TEST_PROGRAMS))

alias.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ static int config_alias_cb(const char *key, const char *value,
2121
return 0;
2222

2323
if (data->alias) {
24-
if (!strcasecmp(p, data->alias))
25-
return git_config_string((const char **)&data->v,
24+
if (!strcasecmp(p, data->alias)) {
25+
FREE_AND_NULL(data->v);
26+
return git_config_string(&data->v,
2627
key, value);
28+
}
2729
} else if (data->list) {
2830
string_list_append(data->list, p);
2931
}

attr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "tree-walk.h"
2626
#include "object-name.h"
2727

28-
const char *git_attr_tree;
28+
char *git_attr_tree;
2929

3030
const char git_attr__true[] = "(builtin)true";
3131
const char git_attr__false[] = "\0(builtin)false";

attr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,6 @@ const char *git_attr_global_file(void);
236236
/* Return whether the system gitattributes file is enabled and should be used. */
237237
int git_attr_system_is_enabled(void);
238238

239-
extern const char *git_attr_tree;
239+
extern char *git_attr_tree;
240240

241241
#endif /* ATTR_H */

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/checkout.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,12 +1275,12 @@ static void setup_new_branch_info_and_source_tree(
12751275
}
12761276
}
12771277

1278-
static const char *parse_remote_branch(const char *arg,
1279-
struct object_id *rev,
1280-
int could_be_checkout_paths)
1278+
static char *parse_remote_branch(const char *arg,
1279+
struct object_id *rev,
1280+
int could_be_checkout_paths)
12811281
{
12821282
int num_matches = 0;
1283-
const char *remote = unique_tracking_name(arg, rev, &num_matches);
1283+
char *remote = unique_tracking_name(arg, rev, &num_matches);
12841284

12851285
if (remote && could_be_checkout_paths) {
12861286
die(_("'%s' could be both a local file and a tracking branch.\n"
@@ -1316,6 +1316,7 @@ static int parse_branchname_arg(int argc, const char **argv,
13161316
const char **new_branch = &opts->new_branch;
13171317
int argcount = 0;
13181318
const char *arg;
1319+
char *remote = NULL;
13191320
int dash_dash_pos;
13201321
int has_dash_dash = 0;
13211322
int i;
@@ -1416,8 +1417,8 @@ static int parse_branchname_arg(int argc, const char **argv,
14161417
recover_with_dwim = 0;
14171418

14181419
if (recover_with_dwim) {
1419-
const char *remote = parse_remote_branch(arg, rev,
1420-
could_be_checkout_paths);
1420+
remote = parse_remote_branch(arg, rev,
1421+
could_be_checkout_paths);
14211422
if (remote) {
14221423
*new_branch = arg;
14231424
arg = remote;
@@ -1459,6 +1460,7 @@ static int parse_branchname_arg(int argc, const char **argv,
14591460
argc--;
14601461
}
14611462

1463+
free(remote);
14621464
return argcount;
14631465
}
14641466

builtin/commit.c

Lines changed: 2 additions & 2 deletions
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.
@@ -133,7 +133,7 @@ static struct strvec trailer_args = STRVEC_INIT;
133133
* is specified explicitly.
134134
*/
135135
static enum commit_msg_cleanup_mode cleanup_mode;
136-
static const char *cleanup_arg;
136+
static char *cleanup_arg;
137137

138138
static enum commit_whence whence;
139139
static int use_editor = 1, include_status = 1;

builtin/config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static int format_config(const struct config_display_options *opts,
289289
else
290290
strbuf_addstr(buf, v ? "true" : "false");
291291
} else if (opts->type == TYPE_PATH) {
292-
const char *v;
292+
char *v;
293293
if (git_config_pathname(&v, key_, value_) < 0)
294294
return -1;
295295
strbuf_addstr(buf, v);

builtin/credential.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ int cmd_credential(int argc, const char **argv, const char *prefix UNUSED)
3939
} else {
4040
usage(usage_msg);
4141
}
42+
43+
credential_clear(&c);
4244
return 0;
4345
}

0 commit comments

Comments
 (0)