Skip to content

Commit 6a83d90

Browse files
avargitster
authored andcommitted
coccinelle: make use of the "type" FREE_AND_NULL() rule
Apply the result of the just-added coccinelle rule. This manually excludes a few occurrences, mostly things that resulted in many FREE_AND_NULL() on one line, that'll be manually fixed in a subsequent change. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf9f49e commit 6a83d90

37 files changed

+71
-142
lines changed

alias.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ int split_cmdline(char *cmdline, const char ***argv)
4747
src++;
4848
c = cmdline[src];
4949
if (!c) {
50-
free(*argv);
51-
*argv = NULL;
50+
FREE_AND_NULL(*argv);
5251
return -SPLIT_CMDLINE_BAD_ENDING;
5352
}
5453
}
@@ -60,8 +59,7 @@ int split_cmdline(char *cmdline, const char ***argv)
6059
cmdline[dst] = 0;
6160

6261
if (quoted) {
63-
free(*argv);
64-
*argv = NULL;
62+
FREE_AND_NULL(*argv);
6563
return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
6664
}
6765

apply.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3705,8 +3705,7 @@ static int check_preimage(struct apply_state *state,
37053705
is_new:
37063706
patch->is_new = 1;
37073707
patch->is_delete = 0;
3708-
free(patch->old_name);
3709-
patch->old_name = NULL;
3708+
FREE_AND_NULL(patch->old_name);
37103709
return 0;
37113710
}
37123711

attr.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,11 @@ void attr_check_reset(struct attr_check *check)
638638

639639
void attr_check_clear(struct attr_check *check)
640640
{
641-
free(check->items);
642-
check->items = NULL;
641+
FREE_AND_NULL(check->items);
643642
check->alloc = 0;
644643
check->nr = 0;
645644

646-
free(check->all_attrs);
647-
check->all_attrs = NULL;
645+
FREE_AND_NULL(check->all_attrs);
648646
check->all_attrs_nr = 0;
649647

650648
drop_attr_stack(&check->stack);

branch.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
2424
} else {
2525
free(tracking->spec.src);
2626
if (tracking->src) {
27-
free(tracking->src);
28-
tracking->src = NULL;
27+
FREE_AND_NULL(tracking->src);
2928
}
3029
}
3130
tracking->spec.src = NULL;

builtin/am.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,7 @@ static int run_applypatch_msg_hook(struct am_state *state)
483483
ret = run_hook_le(NULL, "applypatch-msg", am_path(state, "final-commit"), NULL);
484484

485485
if (!ret) {
486-
free(state->msg);
487-
state->msg = NULL;
486+
FREE_AND_NULL(state->msg);
488487
if (read_commit_msg(state) < 0)
489488
die(_("'%s' was deleted by the applypatch-msg hook"),
490489
am_path(state, "final-commit"));

builtin/clean.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,7 @@ static void interactive_main_loop(void)
837837
int ret;
838838
ret = menus[*chosen].fn();
839839
if (ret != MENU_RETURN_NO_LOOP) {
840-
free(chosen);
841-
chosen = NULL;
840+
FREE_AND_NULL(chosen);
842841
if (!del_list.nr) {
843842
clean_print_color(CLEAN_COLOR_ERROR);
844843
printf_ln(_("No more files to clean, exiting."));
@@ -851,8 +850,7 @@ static void interactive_main_loop(void)
851850
quit_cmd();
852851
}
853852

854-
free(chosen);
855-
chosen = NULL;
853+
FREE_AND_NULL(chosen);
856854
break;
857855
}
858856
}

builtin/config.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ static int get_value(const char *key_, const char *regex_)
214214
key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
215215
if (regcomp(key_regexp, key, REG_EXTENDED)) {
216216
error("invalid key pattern: %s", key_);
217-
free(key_regexp);
218-
key_regexp = NULL;
217+
FREE_AND_NULL(key_regexp);
219218
ret = CONFIG_INVALID_PATTERN;
220219
goto free_strings;
221220
}
@@ -235,8 +234,7 @@ static int get_value(const char *key_, const char *regex_)
235234
regexp = (regex_t*)xmalloc(sizeof(regex_t));
236235
if (regcomp(regexp, regex_, REG_EXTENDED)) {
237236
error("invalid pattern: %s", regex_);
238-
free(regexp);
239-
regexp = NULL;
237+
FREE_AND_NULL(regexp);
240238
ret = CONFIG_INVALID_PATTERN;
241239
goto free_strings;
242240
}

builtin/index-pack.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,7 @@ static struct base_data *alloc_base_data(void)
388388
static void free_base_data(struct base_data *c)
389389
{
390390
if (c->data) {
391-
free(c->data);
392-
c->data = NULL;
391+
FREE_AND_NULL(c->data);
393392
get_thread_data()->base_cache_used -= c->size;
394393
}
395394
}
@@ -605,8 +604,7 @@ static void *unpack_data(struct object_entry *obj,
605604
git_inflate_end(&stream);
606605
free(inbuf);
607606
if (consume) {
608-
free(data);
609-
data = NULL;
607+
FREE_AND_NULL(data);
610608
}
611609
return data;
612610
}

builtin/pack-objects.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
264264
* make sure no cached delta data remains from a
265265
* previous attempt before a pack split occurred.
266266
*/
267-
free(entry->delta_data);
268-
entry->delta_data = NULL;
267+
FREE_AND_NULL(entry->delta_data);
269268
entry->z_delta_size = 0;
270269
} else if (entry->delta_data) {
271270
size = entry->delta_size;
@@ -1375,12 +1374,10 @@ static void cleanup_preferred_base(void)
13751374
if (!pbase_tree_cache[i])
13761375
continue;
13771376
free(pbase_tree_cache[i]->tree_data);
1378-
free(pbase_tree_cache[i]);
1379-
pbase_tree_cache[i] = NULL;
1377+
FREE_AND_NULL(pbase_tree_cache[i]);
13801378
}
13811379

1382-
free(done_pbase_paths);
1383-
done_pbase_paths = NULL;
1380+
FREE_AND_NULL(done_pbase_paths);
13841381
done_pbase_paths_num = done_pbase_paths_alloc = 0;
13851382
}
13861383

@@ -1970,8 +1967,7 @@ static unsigned long free_unpacked(struct unpacked *n)
19701967
n->index = NULL;
19711968
if (n->data) {
19721969
freed_mem += n->entry->size;
1973-
free(n->data);
1974-
n->data = NULL;
1970+
FREE_AND_NULL(n->data);
19751971
}
19761972
n->entry = NULL;
19771973
n->depth = 0;

builtin/unpack-objects.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ static void *get_data(unsigned long size)
112112
break;
113113
if (ret != Z_OK) {
114114
error("inflate returned %d", ret);
115-
free(buf);
116-
buf = NULL;
115+
FREE_AND_NULL(buf);
117116
if (!recover)
118117
exit(1);
119118
has_errors = 1;

0 commit comments

Comments
 (0)