summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2017-06-24 14:28:41 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-06-24 14:28:41 -0700
commit50f03c6676ed5ea040dd53272882d3aac2ee1b48 (patch)
tree8bf9680918762ffa077832674da9cca98c8c1888
parentMerge branch 'jk/warn-add-gitlink' (diff)
parent*.[ch] refactoring: make use of the FREE_AND_NULL() macro (diff)
downloadtgif-50f03c6676ed5ea040dd53272882d3aac2ee1b48.tar.xz
Merge branch 'ab/free-and-null'
A common pattern to free a piece of memory and assign NULL to the pointer that used to point at it has been replaced with a new FREE_AND_NULL() macro. * ab/free-and-null: *.[ch] refactoring: make use of the FREE_AND_NULL() macro coccinelle: make use of the "expression" FREE_AND_NULL() rule coccinelle: add a rule to make "expression" code use FREE_AND_NULL() coccinelle: make use of the "type" FREE_AND_NULL() rule coccinelle: add a rule to make "type" code use FREE_AND_NULL() git-compat-util: add a FREE_AND_NULL() wrapper around free(ptr); ptr = NULL
-rw-r--r--alias.c6
-rw-r--r--apply.c3
-rw-r--r--attr.c6
-rw-r--r--blame.c3
-rw-r--r--branch.c3
-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
-rw-r--r--commit-slab.h3
-rw-r--r--commit.c3
-rw-r--r--config.c3
-rw-r--r--contrib/coccinelle/free.cocci15
-rw-r--r--credential.c9
-rw-r--r--diff-lib.c3
-rw-r--r--diff.c6
-rw-r--r--diffcore-rename.c6
-rw-r--r--dir.c9
-rw-r--r--fast-import.c6
-rw-r--r--git-compat-util.h6
-rw-r--r--gpg-interface.c15
-rw-r--r--grep.c12
-rw-r--r--help.c3
-rw-r--r--http-push.c24
-rw-r--r--http.c15
-rw-r--r--imap-send.c3
-rw-r--r--line-log.c6
-rw-r--r--ll-merge.c3
-rw-r--r--mailinfo.c3
-rw-r--r--object.c3
-rw-r--r--pathspec.c3
-rw-r--r--prio-queue.c3
-rw-r--r--read-cache.c6
-rw-r--r--ref-filter.c3
-rw-r--r--refs/files-backend.c3
-rw-r--r--refs/ref-cache.c3
-rw-r--r--remote-testsvn.c3
-rw-r--r--rerere.c3
-rw-r--r--sequencer.c3
-rw-r--r--sha1-array.c3
-rw-r--r--sha1_file.c3
-rw-r--r--split-index.c3
-rw-r--r--transport-helper.c27
-rw-r--r--transport.c3
-rw-r--r--tree-diff.c6
-rw-r--r--tree.c3
49 files changed, 117 insertions, 195 deletions
diff --git a/alias.c b/alias.c
index de8e6a3f49..39f622e414 100644
--- a/alias.c
+++ b/alias.c
@@ -62,8 +62,7 @@ int split_cmdline(char *cmdline, const char ***argv)
src++;
c = cmdline[src];
if (!c) {
- free(*argv);
- *argv = NULL;
+ FREE_AND_NULL(*argv);
return -SPLIT_CMDLINE_BAD_ENDING;
}
}
@@ -75,8 +74,7 @@ int split_cmdline(char *cmdline, const char ***argv)
cmdline[dst] = 0;
if (quoted) {
- free(*argv);
- *argv = NULL;
+ FREE_AND_NULL(*argv);
return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
}
diff --git a/apply.c b/apply.c
index f7251ccc8b..b963d7d8fb 100644
--- a/apply.c
+++ b/apply.c
@@ -3695,8 +3695,7 @@ static int check_preimage(struct apply_state *state,
is_new:
patch->is_new = 1;
patch->is_delete = 0;
- free(patch->old_name);
- patch->old_name = NULL;
+ FREE_AND_NULL(patch->old_name);
return 0;
}
diff --git a/attr.c b/attr.c
index 6e4b247acd..37454999d2 100644
--- a/attr.c
+++ b/attr.c
@@ -639,13 +639,11 @@ void attr_check_reset(struct attr_check *check)
void attr_check_clear(struct attr_check *check)
{
- free(check->items);
- check->items = NULL;
+ FREE_AND_NULL(check->items);
check->alloc = 0;
check->nr = 0;
- free(check->all_attrs);
- check->all_attrs = NULL;
+ FREE_AND_NULL(check->all_attrs);
check->all_attrs_nr = 0;
drop_attr_stack(&check->stack);
diff --git a/blame.c b/blame.c
index 6d57ab9715..91e26e93e8 100644
--- a/blame.c
+++ b/blame.c
@@ -314,8 +314,7 @@ static void fill_origin_blob(struct diff_options *opt,
static void drop_origin_blob(struct blame_origin *o)
{
if (o->file.ptr) {
- free(o->file.ptr);
- o->file.ptr = NULL;
+ FREE_AND_NULL(o->file.ptr);
}
}
diff --git a/branch.c b/branch.c
index a8a548ccf2..36541d05cd 100644
--- a/branch.c
+++ b/branch.c
@@ -25,8 +25,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
} else {
free(tracking->spec.src);
if (tracking->src) {
- free(tracking->src);
- tracking->src = NULL;
+ FREE_AND_NULL(tracking->src);
}
}
tracking->spec.src = NULL;
diff --git a/builtin/am.c b/builtin/am.c
index 7c7b916d23..c973bd96dc 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 ed954134d2..057fc97fe4 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 82db29fae7..70ff231e9c 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 edc1a91d89..ad4de35178 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 d5e96ed2d0..f4a8441fe9 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 193f8b9d57..689a29fac1 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 0c5476ee9d..c98e2ce5f5 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) {
diff --git a/commit-slab.h b/commit-slab.h
index 42d16dcded..333d81e370 100644
--- a/commit-slab.h
+++ b/commit-slab.h
@@ -82,8 +82,7 @@ static MAYBE_UNUSED void clear_ ##slabname(struct slabname *s) \
for (i = 0; i < s->slab_count; i++) \
free(s->slab[i]); \
s->slab_count = 0; \
- free(s->slab); \
- s->slab = NULL; \
+ FREE_AND_NULL(s->slab); \
} \
\
static MAYBE_UNUSED elemtype *slabname## _at_peek(struct slabname *s, \
diff --git a/commit.c b/commit.c
index 99846d9bf4..cbfd689939 100644
--- a/commit.c
+++ b/commit.c
@@ -287,8 +287,7 @@ void free_commit_buffer(struct commit *commit)
{
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
if (v) {
- free(v->buffer);
- v->buffer = NULL;
+ FREE_AND_NULL(v->buffer);
v->size = 0;
}
}
diff --git a/config.c b/config.c
index 6f0f8b30f3..1cd40a5fe6 100644
--- a/config.c
+++ b/config.c
@@ -394,8 +394,7 @@ static int git_config_parse_key_1(const char *key, char **store_key, int *basele
out_free_ret_1:
if (store_key) {
- free(*store_key);
- *store_key = NULL;
+ FREE_AND_NULL(*store_key);
}
return -CONFIG_INVALID_KEY;
}
diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci
index c03ba737e5..f2d97e755b 100644
--- a/contrib/coccinelle/free.cocci
+++ b/contrib/coccinelle/free.cocci
@@ -9,3 +9,18 @@ expression E;
@@
- if (!E)
free(E);
+
+@@
+type T;
+T *ptr;
+@@
+- free(ptr);
+- ptr = NULL;
++ FREE_AND_NULL(ptr);
+
+@@
+expression E;
+@@
+- free(E);
+- E = NULL;
++ FREE_AND_NULL(E);
diff --git a/credential.c b/credential.c
index 67a523353b..9747f47b18 100644
--- a/credential.c
+++ b/credential.c
@@ -94,8 +94,7 @@ static void credential_apply_config(struct credential *c)
c->configured = 1;
if (!c->use_http_path && proto_is_http(c->protocol)) {
- free(c->path);
- c->path = NULL;
+ FREE_AND_NULL(c->path);
}
}
@@ -315,10 +314,8 @@ void credential_reject(struct credential *c)
for (i = 0; i < c->helpers.nr; i++)
credential_do(c, c->helpers.items[i].string, "erase");
- free(c->username);
- c->username = NULL;
- free(c->password);
- c->password = NULL;
+ FREE_AND_NULL(c->username);
+ FREE_AND_NULL(c->password);
c->approved = 0;
}
diff --git a/diff-lib.c b/diff-lib.c
index 0c0e20f7c0..2a52b07954 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -179,8 +179,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
free(dpath);
continue;
}
- free(dpath);
- dpath = NULL;
+ FREE_AND_NULL(dpath);
/*
* Show the diff for the 'ce' if we found the one
diff --git a/diff.c b/diff.c
index 41295d4ea9..00b4c86698 100644
--- a/diff.c
+++ b/diff.c
@@ -1219,8 +1219,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata)
regfree(ecbdata->diff_words->word_regex);
free(ecbdata->diff_words->word_regex);
}
- free(ecbdata->diff_words);
- ecbdata->diff_words = NULL;
+ FREE_AND_NULL(ecbdata->diff_words);
}
}
@@ -2952,8 +2951,7 @@ void diff_free_filespec_blob(struct diff_filespec *s)
void diff_free_filespec_data(struct diff_filespec *s)
{
diff_free_filespec_blob(s);
- free(s->cnt_data);
- s->cnt_data = NULL;
+ FREE_AND_NULL(s->cnt_data);
}
static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 03d1e8d40b..1e4678b7d7 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -667,11 +667,9 @@ void diffcore_rename(struct diff_options *options)
for (i = 0; i < rename_dst_nr; i++)
free_filespec(rename_dst[i].two);
- free(rename_dst);
- rename_dst = NULL;
+ FREE_AND_NULL(rename_dst);
rename_dst_nr = rename_dst_alloc = 0;
- free(rename_src);
- rename_src = NULL;
+ FREE_AND_NULL(rename_src);
rename_src_nr = rename_src_alloc = 0;
return;
}
diff --git a/dir.c b/dir.c
index f6795473f7..332f9d8095 100644
--- a/dir.c
+++ b/dir.c
@@ -2127,8 +2127,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
for (i = j = 0; j < dir->nr; j++) {
if (i &&
check_dir_entry_contains(dir->entries[i - 1], dir->entries[j])) {
- free(dir->entries[j]);
- dir->entries[j] = NULL;
+ FREE_AND_NULL(dir->entries[j]);
} else {
dir->entries[i++] = dir->entries[j];
}
@@ -2154,8 +2153,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
dir->untracked->dir_invalidated))
istate->cache_changed |= UNTRACKED_CHANGED;
if (dir->untracked != istate->untracked) {
- free(dir->untracked);
- dir->untracked = NULL;
+ FREE_AND_NULL(dir->untracked);
}
}
return dir->nr;
@@ -2498,8 +2496,7 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra
strbuf_addbuf(out, &untracked->ident);
strbuf_add(out, ouc, ouc_size(len));
- free(ouc);
- ouc = NULL;
+ FREE_AND_NULL(ouc);
if (!untracked->root) {
varint_len = encode_varint(0, varbuf);
diff --git a/fast-import.c b/fast-import.c
index 12b90fe9e3..a959161b46 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1064,8 +1064,7 @@ discard_pack:
close(pack_data->pack_fd);
unlink_or_warn(pack_data->pack_name);
}
- free(pack_data);
- pack_data = NULL;
+ FREE_AND_NULL(pack_data);
running = 0;
/* We can't carry a delta across packfiles. */
@@ -1150,8 +1149,7 @@ static int store_object(
/* We cannot carry a delta into the new pack. */
if (delta) {
- free(delta);
- delta = NULL;
+ FREE_AND_NULL(delta);
git_deflate_init(&s, pack_compression_level);
s.next_in = (void *)dat->buf;
diff --git a/git-compat-util.h b/git-compat-util.h
index 51ba4e6b3b..047172d173 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -808,6 +808,12 @@ extern char *xgetcwd(void);
extern FILE *fopen_for_writing(const char *path);
extern FILE *fopen_or_warn(const char *path, const char *mode);
+/*
+ * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note
+ * that ptr is used twice, so don't pass e.g. ptr++.
+ */
+#define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)
+
#define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))
#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))
diff --git a/gpg-interface.c b/gpg-interface.c
index 8ab32df457..d936f3a32f 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -14,16 +14,11 @@ static const char *gpg_program = "gpg";
void signature_check_clear(struct signature_check *sigc)
{
- free(sigc->payload);
- free(sigc->gpg_output);
- free(sigc->gpg_status);
- free(sigc->signer);
- free(sigc->key);
- sigc->payload = NULL;
- sigc->gpg_output = NULL;
- sigc->gpg_status = NULL;
- sigc->signer = NULL;
- sigc->key = NULL;
+ FREE_AND_NULL(sigc->payload);
+ FREE_AND_NULL(sigc->gpg_output);
+ FREE_AND_NULL(sigc->gpg_status);
+ FREE_AND_NULL(sigc->signer);
+ FREE_AND_NULL(sigc->key);
}
static struct {
diff --git a/grep.c b/grep.c
index 1fca83be86..98733db623 100644
--- a/grep.c
+++ b/grep.c
@@ -1940,12 +1940,9 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type,
void grep_source_clear(struct grep_source *gs)
{
- free(gs->name);
- gs->name = NULL;
- free(gs->path);
- gs->path = NULL;
- free(gs->identifier);
- gs->identifier = NULL;
+ FREE_AND_NULL(gs->name);
+ FREE_AND_NULL(gs->path);
+ FREE_AND_NULL(gs->identifier);
grep_source_clear_data(gs);
}
@@ -1955,8 +1952,7 @@ void grep_source_clear_data(struct grep_source *gs)
case GREP_SOURCE_FILE:
case GREP_SOURCE_OID:
case GREP_SOURCE_SUBMODULE:
- free(gs->buf);
- gs->buf = NULL;
+ FREE_AND_NULL(gs->buf);
gs->size = 0;
break;
case GREP_SOURCE_BUF:
diff --git a/help.c b/help.c
index 8ba0777410..07b185389d 100644
--- a/help.c
+++ b/help.c
@@ -269,9 +269,8 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
for (i = 0; i < old->cnt; i++)
cmds->names[cmds->cnt++] = old->names[i];
- free(old->names);
+ FREE_AND_NULL(old->names);
old->cnt = 0;
- old->names = NULL;
}
/* An empirically derived magic number */
diff --git a/http-push.c b/http-push.c
index 67c4d4b472..c91f40a610 100644
--- a/http-push.c
+++ b/http-push.c
@@ -291,8 +291,7 @@ static void start_mkcol(struct transfer_request *request)
request->state = RUN_MKCOL;
} else {
request->state = ABORTED;
- free(request->url);
- request->url = NULL;
+ FREE_AND_NULL(request->url);
}
}
#endif
@@ -409,8 +408,7 @@ static void start_put(struct transfer_request *request)
request->state = RUN_PUT;
} else {
request->state = ABORTED;
- free(request->url);
- request->url = NULL;
+ FREE_AND_NULL(request->url);
}
}
@@ -432,8 +430,7 @@ static void start_move(struct transfer_request *request)
request->state = RUN_MOVE;
} else {
request->state = ABORTED;
- free(request->url);
- request->url = NULL;
+ FREE_AND_NULL(request->url);
}
}
@@ -526,8 +523,7 @@ static void finish_request(struct transfer_request *request)
/* URL is reused for MOVE after PUT */
if (request->state != RUN_PUT) {
- free(request->url);
- request->url = NULL;
+ FREE_AND_NULL(request->url);
}
if (request->state == RUN_MKCOL) {
@@ -803,8 +799,7 @@ xml_start_tag(void *userData, const char *name, const char **atts)
}
xsnprintf(ctx->name + old_namelen, ctx->len - old_namelen, ".%s", c);
- free(ctx->cdata);
- ctx->cdata = NULL;
+ FREE_AND_NULL(ctx->cdata);
ctx->userFunc(ctx, 0);
}
@@ -932,8 +927,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
free(lock->token);
free(lock->owner);
free(url);
- free(lock);
- lock = NULL;
+ FREE_AND_NULL(lock);
} else {
lock->url = url;
lock->start_time = time(NULL);
@@ -1105,8 +1099,7 @@ static void handle_remote_ls_ctx(struct xml_ctx *ctx, int tag_closed)
ls->dentry_flags |= IS_DIR;
}
} else if (!strcmp(ctx->name, DAV_PROPFIND_RESP)) {
- free(ls->dentry_name);
- ls->dentry_name = NULL;
+ FREE_AND_NULL(ls->dentry_name);
ls->dentry_flags = 0;
}
}
@@ -1547,8 +1540,7 @@ static void fetch_symref(const char *path, char **symref, struct object_id *oid)
curl_errorstr);
free(url);
- free(*symref);
- *symref = NULL;
+ FREE_AND_NULL(*symref);
oidclr(oid);
if (buffer.len == 0)
diff --git a/http.c b/http.c
index 013bb0cc65..c6c010f881 100644
--- a/http.c
+++ b/http.c
@@ -1027,8 +1027,7 @@ void http_cleanup(void)
if (proxy_auth.password) {
memset(proxy_auth.password, 0, strlen(proxy_auth.password));
- free(proxy_auth.password);
- proxy_auth.password = NULL;
+ FREE_AND_NULL(proxy_auth.password);
}
free((void *)curl_proxyuserpwd);
@@ -1039,13 +1038,11 @@ void http_cleanup(void)
if (cert_auth.password != NULL) {
memset(cert_auth.password, 0, strlen(cert_auth.password));
- free(cert_auth.password);
- cert_auth.password = NULL;
+ FREE_AND_NULL(cert_auth.password);
}
ssl_cert_password_required = 0;
- free(cached_accept_language);
- cached_accept_language = NULL;
+ FREE_AND_NULL(cached_accept_language);
}
struct active_request_slot *get_active_slot(void)
@@ -1897,8 +1894,7 @@ static char *fetch_pack_index(unsigned char *sha1, const char *base_url)
if (http_get_file(url, tmp, NULL) != HTTP_OK) {
error("Unable to get pack index %s", url);
- free(tmp);
- tmp = NULL;
+ FREE_AND_NULL(tmp);
}
free(url);
@@ -2329,8 +2325,7 @@ void release_http_object_request(struct http_object_request *freq)
freq->localfile = -1;
}
if (freq->url != NULL) {
- free(freq->url);
- freq->url = NULL;
+ FREE_AND_NULL(freq->url);
}
if (freq->slot != NULL) {
freq->slot->callback_func = NULL;
diff --git a/imap-send.c b/imap-send.c
index 59e9b12d29..351e84aea1 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -777,8 +777,7 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
offsetof(struct imap_cmd, next));
if (cmdp->cb.data) {
n = socket_write(&imap->buf.sock, cmdp->cb.data, cmdp->cb.dlen);
- free(cmdp->