summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/am.c18
-rw-r--r--builtin/clean.c6
-rw-r--r--builtin/config.c6
-rw-r--r--builtin/index-pack.c6
-rw-r--r--builtin/pack-objects.c12
-rw-r--r--builtin/unpack-objects.c3
-rw-r--r--builtin/worktree.c6
7 files changed, 18 insertions, 39 deletions
diff --git a/builtin/am.c b/builtin/am.c
index 7c7b916..c973bd9 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -484,8 +484,7 @@ static int run_applypatch_msg_hook(struct am_state *state)
ret = run_hook_le(NULL, "applypatch-msg", am_path(state, "final-commit"), NULL);
if (!ret) {
- free(state->msg);
- state->msg = NULL;
+ FREE_AND_NULL(state->msg);
if (read_commit_msg(state) < 0)
die(_("'%s' was deleted by the applypatch-msg hook"),
am_path(state, "final-commit"));
@@ -1074,17 +1073,10 @@ static void am_next(struct am_state *state)
{
struct object_id head;
- free(state->author_name);
- state->author_name = NULL;
-
- free(state->author_email);
- state->author_email = NULL;
-
- free(state->author_date);
- state->author_date = NULL;
-
- free(state->msg);
- state->msg = NULL;
+ FREE_AND_NULL(state->author_name);
+ FREE_AND_NULL(state->author_email);
+ FREE_AND_NULL(state->author_date);
+ FREE_AND_NULL(state->msg);
state->msg_len = 0;
unlink(am_path(state, "author-script"));
diff --git a/builtin/clean.c b/builtin/clean.c
index ed95413..057fc97 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -838,8 +838,7 @@ static void interactive_main_loop(void)
int ret;
ret = menus[*chosen].fn();
if (ret != MENU_RETURN_NO_LOOP) {
- free(chosen);
- chosen = NULL;
+ FREE_AND_NULL(chosen);
if (!del_list.nr) {
clean_print_color(CLEAN_COLOR_ERROR);
printf_ln(_("No more files to clean, exiting."));
@@ -852,8 +851,7 @@ static void interactive_main_loop(void)
quit_cmd();
}
- free(chosen);
- chosen = NULL;
+ FREE_AND_NULL(chosen);
break;
}
}
diff --git a/builtin/config.c b/builtin/config.c
index 82db29f..70ff231 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -215,8 +215,7 @@ static int get_value(const char *key_, const char *regex_)
key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
if (regcomp(key_regexp, key, REG_EXTENDED)) {
error("invalid key pattern: %s", key_);
- free(key_regexp);
- key_regexp = NULL;
+ FREE_AND_NULL(key_regexp);
ret = CONFIG_INVALID_PATTERN;
goto free_strings;
}
@@ -236,8 +235,7 @@ static int get_value(const char *key_, const char *regex_)
regexp = (regex_t*)xmalloc(sizeof(regex_t));
if (regcomp(regexp, regex_, REG_EXTENDED)) {
error("invalid pattern: %s", regex_);
- free(regexp);
- regexp = NULL;
+ FREE_AND_NULL(regexp);
ret = CONFIG_INVALID_PATTERN;
goto free_strings;
}
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index edc1a91..ad4de35 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -389,8 +389,7 @@ static struct base_data *alloc_base_data(void)
static void free_base_data(struct base_data *c)
{
if (c->data) {
- free(c->data);
- c->data = NULL;
+ FREE_AND_NULL(c->data);
get_thread_data()->base_cache_used -= c->size;
}
}
@@ -606,8 +605,7 @@ static void *unpack_data(struct object_entry *obj,
git_inflate_end(&stream);
free(inbuf);
if (consume) {
- free(data);
- data = NULL;
+ FREE_AND_NULL(data);
}
return data;
}
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index d5e96ed..f4a8441 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -265,8 +265,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
* make sure no cached delta data remains from a
* previous attempt before a pack split occurred.
*/
- free(entry->delta_data);
- entry->delta_data = NULL;
+ FREE_AND_NULL(entry->delta_data);
entry->z_delta_size = 0;
} else if (entry->delta_data) {
size = entry->delta_size;
@@ -1376,12 +1375,10 @@ static void cleanup_preferred_base(void)
if (!pbase_tree_cache[i])
continue;
free(pbase_tree_cache[i]->tree_data);
- free(pbase_tree_cache[i]);
- pbase_tree_cache[i] = NULL;
+ FREE_AND_NULL(pbase_tree_cache[i]);
}
- free(done_pbase_paths);
- done_pbase_paths = NULL;
+ FREE_AND_NULL(done_pbase_paths);
done_pbase_paths_num = done_pbase_paths_alloc = 0;
}
@@ -1971,8 +1968,7 @@ static unsigned long free_unpacked(struct unpacked *n)
n->index = NULL;
if (n->data) {
freed_mem += n->entry->size;
- free(n->data);
- n->data = NULL;
+ FREE_AND_NULL(n->data);
}
n->entry = NULL;
n->depth = 0;
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 193f8b9..689a29f 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -113,8 +113,7 @@ static void *get_data(unsigned long size)
break;
if (ret != Z_OK) {
error("inflate returned %d", ret);
- free(buf);
- buf = NULL;
+ FREE_AND_NULL(buf);
if (!recover)
exit(1);
has_errors = 1;
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 0c5476e..c98e2ce 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -300,10 +300,8 @@ static int add_worktree(const char *path, const char *refname,
}
is_junk = 0;
- free(junk_work_tree);
- free(junk_git_dir);
- junk_work_tree = NULL;
- junk_git_dir = NULL;
+ FREE_AND_NULL(junk_work_tree);
+ FREE_AND_NULL(junk_git_dir);
done:
if (ret || !opts->keep_locked) {