1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-04-28 08:35:23 +02:00

*.[ch] refactoring: make use of the FREE_AND_NULL() macro

Replace occurrences of `free(ptr); ptr = NULL` which weren't caught by
the coccinelle rule. These fall into two categories:

 - free/NULL assignments one after the other which coccinelle all put
   on one line, which is functionally equivalent code, but very ugly.

 - manually spotted occurrences where the NULL assignment isn't right
   after the free() call.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2017-06-15 23:15:49 +00:00 committed by Junio C Hamano
parent e140f7afdd
commit 88ce3ef636
12 changed files with 23 additions and 49 deletions

View File

@ -1072,17 +1072,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"));

View File

@ -299,10 +299,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) {

View File

@ -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, \

View File

@ -313,10 +313,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;
}

View File

@ -13,16 +13,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 {

9
grep.c
View File

@ -1763,12 +1763,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);
}

3
help.c
View File

@ -267,9 +267,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 */

View File

@ -34,9 +34,8 @@ void range_set_init(struct range_set *rs, size_t prealloc)
void range_set_release(struct range_set *rs)
{
free(rs->ranges);
FREE_AND_NULL(rs->ranges);
rs->alloc = rs->nr = 0;
rs->ranges = NULL;
}
/* dst must be uninitialized! */

View File

@ -27,10 +27,9 @@ void prio_queue_reverse(struct prio_queue *queue)
void clear_prio_queue(struct prio_queue *queue)
{
free(queue->array);
FREE_AND_NULL(queue->array);
queue->nr = 0;
queue->alloc = 0;
queue->array = NULL;
queue->insertion_ctr = 0;
}

View File

@ -82,9 +82,8 @@ static void clear_ref_dir(struct ref_dir *dir)
int i;
for (i = 0; i < dir->nr; i++)
free_ref_entry(dir->entries[i]);
free(dir->entries);
FREE_AND_NULL(dir->entries);
dir->sorted = dir->nr = dir->alloc = 0;
dir->entries = NULL;
}
struct ref_entry *create_dir_entry(struct ref_cache *cache,

View File

@ -39,9 +39,8 @@ static void free_rerere_dirs(void)
free(rerere_dir[i]->status);
free(rerere_dir[i]);
}
free(rerere_dir);
FREE_AND_NULL(rerere_dir);
rerere_dir_nr = rerere_dir_alloc = 0;
rerere_dir = NULL;
}
static void free_rerere_id(struct string_list_item *item)

View File

@ -174,10 +174,9 @@ void merge_base_index(struct index_state *istate)
ewah_free(si->delete_bitmap);
ewah_free(si->replace_bitmap);
free(si->saved_cache);
FREE_AND_NULL(si->saved_cache);
si->delete_bitmap = NULL;
si->replace_bitmap = NULL;
si->saved_cache = NULL;
si->saved_cache_nr = 0;
}