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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jun 15, 2017 at 23:15 UTC 6a83d902073803c4141e02c53decf8c03e35da27
37 files changed +71 -142
alias.c
+2 -4
@@ -47,8 +47,7 @@ int split_cmdline(char *cmdline, const char ***argv)
47 src++;
48 c = cmdline[src];
49 if (!c) {
50 - free(*argv);
51 - *argv = NULL;
50 + FREE_AND_NULL(*argv);
51 return -SPLIT_CMDLINE_BAD_ENDING;
52 }
53 }
@@ -60,8 +59,7 @@ int split_cmdline(char *cmdline, const char ***argv)
59 cmdline[dst] = 0;
60
61 if (quoted) {
63 - free(*argv);
64 - *argv = NULL;
62 + FREE_AND_NULL(*argv);
63 return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
64 }
65
apply.c
+1 -2
@@ -3705,8 +3705,7 @@ static int check_preimage(struct apply_state *state,
3705 is_new:
3706 patch->is_new = 1;
3707 patch->is_delete = 0;
3708 - free(patch->old_name);
3709 - patch->old_name = NULL;
3708 + FREE_AND_NULL(patch->old_name);
3709 return 0;
3710 }
3711
attr.c
+2 -4
@@ -638,13 +638,11 @@ void attr_check_reset(struct attr_check *check)
638
639 void attr_check_clear(struct attr_check *check)
640 {
641 - free(check->items);
642 - check->items = NULL;
641 + FREE_AND_NULL(check->items);
642 check->alloc = 0;
643 check->nr = 0;
644
646 - free(check->all_attrs);
647 - check->all_attrs = NULL;
645 + FREE_AND_NULL(check->all_attrs);
646 check->all_attrs_nr = 0;
647
648 drop_attr_stack(&check->stack);
branch.c
+1 -2
@@ -24,8 +24,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
24 } else {
25 free(tracking->spec.src);
26 if (tracking->src) {
27 - free(tracking->src);
28 - tracking->src = NULL;
27 + FREE_AND_NULL(tracking->src);
28 }
29 }
30 tracking->spec.src = NULL;
builtin/am.c
+1 -2
@@ -483,8 +483,7 @@ static int run_applypatch_msg_hook(struct am_state *state)
483 ret = run_hook_le(NULL, "applypatch-msg", am_path(state, "final-commit"), NULL);
484
485 if (!ret) {
486 - free(state->msg);
487 - state->msg = NULL;
486 + FREE_AND_NULL(state->msg);
487 if (read_commit_msg(state) < 0)
488 die(_("'%s' was deleted by the applypatch-msg hook"),
489 am_path(state, "final-commit"));
builtin/clean.c
+2 -4
@@ -837,8 +837,7 @@ static void interactive_main_loop(void)
837 int ret;
838 ret = menus[*chosen].fn();
839 if (ret != MENU_RETURN_NO_LOOP) {
840 - free(chosen);
841 - chosen = NULL;
840 + FREE_AND_NULL(chosen);
841 if (!del_list.nr) {
842 clean_print_color(CLEAN_COLOR_ERROR);
843 printf_ln(_("No more files to clean, exiting."));
@@ -851,8 +850,7 @@ static void interactive_main_loop(void)
850 quit_cmd();
851 }
852
854 - free(chosen);
855 - chosen = NULL;
853 + FREE_AND_NULL(chosen);
854 break;
855 }
856 }
builtin/config.c
+2 -4
@@ -214,8 +214,7 @@ static int get_value(const char *key_, const char *regex_)
214 key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
215 if (regcomp(key_regexp, key, REG_EXTENDED)) {
216 error("invalid key pattern: %s", key_);
217 - free(key_regexp);
218 - key_regexp = NULL;
217 + FREE_AND_NULL(key_regexp);
218 ret = CONFIG_INVALID_PATTERN;
219 goto free_strings;
220 }
@@ -235,8 +234,7 @@ static int get_value(const char *key_, const char *regex_)
234 regexp = (regex_t*)xmalloc(sizeof(regex_t));
235 if (regcomp(regexp, regex_, REG_EXTENDED)) {
236 error("invalid pattern: %s", regex_);
238 - free(regexp);
239 - regexp = NULL;
237 + FREE_AND_NULL(regexp);
238 ret = CONFIG_INVALID_PATTERN;
239 goto free_strings;
240 }
builtin/index-pack.c
+2 -4
@@ -388,8 +388,7 @@ static struct base_data *alloc_base_data(void)
388 static void free_base_data(struct base_data *c)
389 {
390 if (c->data) {
391 - free(c->data);
392 - c->data = NULL;
391 + FREE_AND_NULL(c->data);
392 get_thread_data()->base_cache_used -= c->size;
393 }
394 }
@@ -605,8 +604,7 @@ static void *unpack_data(struct object_entry *obj,
604 git_inflate_end(&stream);
605 free(inbuf);
606 if (consume) {
608 - free(data);
609 - data = NULL;
607 + FREE_AND_NULL(data);
608 }
609 return data;
610 }
builtin/pack-objects.c
+4 -8
@@ -264,8 +264,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
264 * make sure no cached delta data remains from a
265 * previous attempt before a pack split occurred.
266 */
267 - free(entry->delta_data);
268 - entry->delta_data = NULL;
267 + FREE_AND_NULL(entry->delta_data);
268 entry->z_delta_size = 0;
269 } else if (entry->delta_data) {
270 size = entry->delta_size;
@@ -1375,12 +1374,10 @@ static void cleanup_preferred_base(void)
1374 if (!pbase_tree_cache[i])
1375 continue;
1376 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]);
1378 }
1379
1382 - free(done_pbase_paths);
1383 - done_pbase_paths = NULL;
1380 + FREE_AND_NULL(done_pbase_paths);
1381 done_pbase_paths_num = done_pbase_paths_alloc = 0;
1382 }
1383
@@ -1970,8 +1967,7 @@ static unsigned long free_unpacked(struct unpacked *n)
1967 n->index = NULL;
1968 if (n->data) {
1969 freed_mem += n->entry->size;
1973 - free(n->data);
1974 - n->data = NULL;
1970 + FREE_AND_NULL(n->data);
1971 }
1972 n->entry = NULL;
1973 n->depth = 0;
builtin/unpack-objects.c
+1 -2
@@ -112,8 +112,7 @@ static void *get_data(unsigned long size)
112 break;
113 if (ret != Z_OK) {
114 error("inflate returned %d", ret);
115 - free(buf);
116 - buf = NULL;
115 + FREE_AND_NULL(buf);
116 if (!recover)
117 exit(1);
118 has_errors = 1;
commit.c
+1 -2
@@ -287,8 +287,7 @@ void free_commit_buffer(struct commit *commit)
287 {
288 struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
289 if (v) {
290 - free(v->buffer);
291 - v->buffer = NULL;
290 + FREE_AND_NULL(v->buffer);
291 v->size = 0;
292 }
293 }
config.c
+1 -2
@@ -395,8 +395,7 @@ static int git_config_parse_key_1(const char *key, char **store_key, int *basele
395
396 out_free_ret_1:
397 if (store_key) {
398 - free(*store_key);
399 - *store_key = NULL;
398 + FREE_AND_NULL(*store_key);
399 }
400 return -CONFIG_INVALID_KEY;
401 }
credential.c
+1 -2
@@ -93,8 +93,7 @@ static void credential_apply_config(struct credential *c)
93 c->configured = 1;
94
95 if (!c->use_http_path && proto_is_http(c->protocol)) {
96 - free(c->path);
97 - c->path = NULL;
96 + FREE_AND_NULL(c->path);
97 }
98 }
99
diff-lib.c
+1 -2
@@ -179,8 +179,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
179 free(dpath);
180 continue;
181 }
182 - free(dpath);
183 - dpath = NULL;
182 + FREE_AND_NULL(dpath);
183
184 /*
185 * Show the diff for the 'ce' if we found the one
diff.c
+2 -4
@@ -1218,8 +1218,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata)
1218 regfree(ecbdata->diff_words->word_regex);
1219 free(ecbdata->diff_words->word_regex);
1220 }
1221 - free(ecbdata->diff_words);
1222 - ecbdata->diff_words = NULL;
1221 + FREE_AND_NULL(ecbdata->diff_words);
1222 }
1223 }
1224
@@ -2951,8 +2950,7 @@ void diff_free_filespec_blob(struct diff_filespec *s)
2950 void diff_free_filespec_data(struct diff_filespec *s)
2951 {
2952 diff_free_filespec_blob(s);
2954 - free(s->cnt_data);
2955 - s->cnt_data = NULL;
2953 + FREE_AND_NULL(s->cnt_data);
2954 }
2955
2956 static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
diffcore-rename.c
+2 -4
@@ -667,11 +667,9 @@ void diffcore_rename(struct diff_options *options)
667 for (i = 0; i < rename_dst_nr; i++)
668 free_filespec(rename_dst[i].two);
669
670 - free(rename_dst);
671 - rename_dst = NULL;
670 + FREE_AND_NULL(rename_dst);
671 rename_dst_nr = rename_dst_alloc = 0;
673 - free(rename_src);
674 - rename_src = NULL;
672 + FREE_AND_NULL(rename_src);
673 rename_src_nr = rename_src_alloc = 0;
674 return;
675 }
dir.c
+3 -6
@@ -2117,8 +2117,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
2117 for (i = j = 0; j < dir->nr; j++) {
2118 if (i &&
2119 check_dir_entry_contains(dir->entries[i - 1], dir->entries[j])) {
2120 - free(dir->entries[j]);
2121 - dir->entries[j] = NULL;
2120 + FREE_AND_NULL(dir->entries[j]);
2121 } else {
2122 dir->entries[i++] = dir->entries[j];
2123 }
@@ -2144,8 +2143,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
2143 dir->untracked->dir_invalidated))
2144 istate->cache_changed |= UNTRACKED_CHANGED;
2145 if (dir->untracked != istate->untracked) {
2147 - free(dir->untracked);
2148 - dir->untracked = NULL;
2146 + FREE_AND_NULL(dir->untracked);
2147 }
2148 }
2149 return dir->nr;
@@ -2488,8 +2486,7 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra
2486 strbuf_addbuf(out, &untracked->ident);
2487
2488 strbuf_add(out, ouc, ouc_size(len));
2491 - free(ouc);
2492 - ouc = NULL;
2489 + FREE_AND_NULL(ouc);
2490
2491 if (!untracked->root) {
2492 varint_len = encode_varint(0, varbuf);
fast-import.c
+2 -4
@@ -1063,8 +1063,7 @@ discard_pack:
1063 close(pack_data->pack_fd);
1064 unlink_or_warn(pack_data->pack_name);
1065 }
1066 - free(pack_data);
1067 - pack_data = NULL;
1066 + FREE_AND_NULL(pack_data);
1067 running = 0;
1068
1069 /* We can't carry a delta across packfiles. */
@@ -1149,8 +1148,7 @@ static int store_object(
1148
1149 /* We cannot carry a delta into the new pack. */
1150 if (delta) {
1152 - free(delta);
1153 - delta = NULL;
1151 + FREE_AND_NULL(delta);
1152
1153 git_deflate_init(&s, pack_compression_level);
1154 s.next_in = (void *)dat->buf;
grep.c
+1 -2
@@ -1778,8 +1778,7 @@ void grep_source_clear_data(struct grep_source *gs)
1778 case GREP_SOURCE_FILE:
1779 case GREP_SOURCE_SHA1:
1780 case GREP_SOURCE_SUBMODULE:
1781 - free(gs->buf);
1782 - gs->buf = NULL;
1781 + FREE_AND_NULL(gs->buf);
1782 gs->size = 0;
1783 break;
1784 case GREP_SOURCE_BUF:
http-push.c
+8 -16
@@ -291,8 +291,7 @@ static void start_mkcol(struct transfer_request *request)
291 request->state = RUN_MKCOL;
292 } else {
293 request->state = ABORTED;
294 - free(request->url);
295 - request->url = NULL;
294 + FREE_AND_NULL(request->url);
295 }
296 }
297 #endif
@@ -409,8 +408,7 @@ static void start_put(struct transfer_request *request)
408 request->state = RUN_PUT;
409 } else {
410 request->state = ABORTED;
412 - free(request->url);
413 - request->url = NULL;
411 + FREE_AND_NULL(request->url);
412 }
413 }
414
@@ -432,8 +430,7 @@ static void start_move(struct transfer_request *request)
430 request->state = RUN_MOVE;
431 } else {
432 request->state = ABORTED;
435 - free(request->url);
436 - request->url = NULL;
433 + FREE_AND_NULL(request->url);
434 }
435 }
436
@@ -526,8 +523,7 @@ static void finish_request(struct transfer_request *request)
523
524 /* URL is reused for MOVE after PUT */
525 if (request->state != RUN_PUT) {
529 - free(request->url);
530 - request->url = NULL;
526 + FREE_AND_NULL(request->url);
527 }
528
529 if (request->state == RUN_MKCOL) {
@@ -803,8 +799,7 @@ xml_start_tag(void *userData, const char *name, const char **atts)
799 }
800 xsnprintf(ctx->name + old_namelen, ctx->len - old_namelen, ".%s", c);
801
806 - free(ctx->cdata);
807 - ctx->cdata = NULL;
802 + FREE_AND_NULL(ctx->cdata);
803
804 ctx->userFunc(ctx, 0);
805 }
@@ -932,8 +927,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
927 free(lock->token);
928 free(lock->owner);
929 free(url);
935 - free(lock);
936 - lock = NULL;
930 + FREE_AND_NULL(lock);
931 } else {
932 lock->url = url;
933 lock->start_time = time(NULL);
@@ -1105,8 +1099,7 @@ static void handle_remote_ls_ctx(struct xml_ctx *ctx, int tag_closed)
1099 ls->dentry_flags |= IS_DIR;
1100 }
1101 } else if (!strcmp(ctx->name, DAV_PROPFIND_RESP)) {
1108 - free(ls->dentry_name);
1109 - ls->dentry_name = NULL;
1102 + FREE_AND_NULL(ls->dentry_name);
1103 ls->dentry_flags = 0;
1104 }
1105 }
@@ -1547,8 +1540,7 @@ static void fetch_symref(const char *path, char **symref, struct object_id *oid)
1540 curl_errorstr);
1541 free(url);
1542
1550 - free(*symref);
1551 - *symref = NULL;
1543 + FREE_AND_NULL(*symref);
1544 oidclr(oid);
1545
1546 if (buffer.len == 0)
http.c
+5 -10
@@ -1026,8 +1026,7 @@ void http_cleanup(void)
1026
1027 if (proxy_auth.password) {
1028 memset(proxy_auth.password, 0, strlen(proxy_auth.password));
1029 - free(proxy_auth.password);
1030 - proxy_auth.password = NULL;
1029 + FREE_AND_NULL(proxy_auth.password);
1030 }
1031
1032 free((void *)curl_proxyuserpwd);
@@ -1038,13 +1037,11 @@ void http_cleanup(void)
1037
1038 if (cert_auth.password != NULL) {
1039 memset(cert_auth.password, 0, strlen(cert_auth.password));
1041 - free(cert_auth.password);
1042 - cert_auth.password = NULL;
1040 + FREE_AND_NULL(cert_auth.password);
1041 }
1042 ssl_cert_password_required = 0;
1043
1046 - free(cached_accept_language);
1047 - cached_accept_language = NULL;
1044 + FREE_AND_NULL(cached_accept_language);
1045 }
1046
1047 struct active_request_slot *get_active_slot(void)
@@ -1896,8 +1893,7 @@ static char *fetch_pack_index(unsigned char *sha1, const char *base_url)
1893
1894 if (http_get_file(url, tmp, NULL) != HTTP_OK) {
1895 error("Unable to get pack index %s", url);
1899 - free(tmp);
1900 - tmp = NULL;
1896 + FREE_AND_NULL(tmp);
1897 }
1898
1899 free(url);
@@ -2328,8 +2324,7 @@ void release_http_object_request(struct http_object_request *freq)
2324 freq->localfile = -1;
2325 }
2326 if (freq->url != NULL) {
2331 - free(freq->url);
2332 - freq->url = NULL;
2327 + FREE_AND_NULL(freq->url);
2328 }
2329 if (freq->slot != NULL) {
2330 freq->slot->callback_func = NULL;
imap-send.c
+1 -2
@@ -776,8 +776,7 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
776 offsetof(struct imap_cmd, next));
777 if (cmdp->cb.data) {
778 n = socket_write(&imap->buf.sock, cmdp->cb.data, cmdp->cb.dlen);
779 - free(cmdp->cb.data);
780 - cmdp->cb.data = NULL;
779 + FREE_AND_NULL(cmdp->cb.data);
780 if (n != (int)cmdp->cb.dlen)
781 return RESP_BAD;
782 } else if (cmdp->cb.cont) {
line-log.c
+1 -2
@@ -610,8 +610,7 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
610 line_log_data_insert(&ranges, full_name, begin, end);
611
612 free_filespec(spec);
613 - free(ends);
614 - ends = NULL;
613 + FREE_AND_NULL(ends);
614 }
615
616 for (p = ranges; p; p = p->next)
mailinfo.c
+1 -2
@@ -919,8 +919,7 @@ again:
919 /* we hit an end boundary */
920 /* pop the current boundary off the stack */
921 strbuf_release(*(mi->content_top));
922 - free(*(mi->content_top));
923 - *(mi->content_top) = NULL;
922 + FREE_AND_NULL(*(mi->content_top));
923
924 /* technically won't happen as is_multipart_boundary()
925 will fail first. But just in case..
object.c
+1 -2
@@ -377,8 +377,7 @@ void object_array_clear(struct object_array *array)
377 int i;
378 for (i = 0; i < array->nr; i++)
379 object_array_release_entry(&array->objects[i]);
380 - free(array->objects);
381 - array->objects = NULL;
380 + FREE_AND_NULL(array->objects);
381 array->nr = array->alloc = 0;
382 }
383
pathspec.c
+1 -2
@@ -662,7 +662,6 @@ void clear_pathspec(struct pathspec *pathspec)
662 attr_check_free(pathspec->items[i].attr_check);
663 }
664
665 - free(pathspec->items);
666 - pathspec->items = NULL;
665 + FREE_AND_NULL(pathspec->items);
666 pathspec->nr = 0;
667 }
read-cache.c
+2 -4
@@ -1888,8 +1888,7 @@ int discard_index(struct index_state *istate)
1888 free_name_hash(istate);
1889 cache_tree_free(&(istate->cache_tree));
1890 istate->initialized = 0;
1891 - free(istate->cache);
1892 - istate->cache = NULL;
1891 + FREE_AND_NULL(istate->cache);
1892 istate->cache_alloc = 0;
1893 discard_split_index(istate);
1894 free_untracked_cache(istate->untracked);
@@ -2603,8 +2602,7 @@ void *read_blob_data_from_index(const struct index_state *istate,
2602
2603 void stat_validity_clear(struct stat_validity *sv)
2604 {
2606 - free(sv->sd);
2607 - sv->sd = NULL;
2605 + FREE_AND_NULL(sv->sd);
2606 }
2607
2608 int stat_validity_check(struct stat_validity *sv, const char *path)
ref-filter.c
+1 -2
@@ -1891,8 +1891,7 @@ void ref_array_clear(struct ref_array *array)
1891
1892 for (i = 0; i < array->nr; i++)
1893 free_array_item(array->items[i]);
1894 - free(array->items);
1895 - array->items = NULL;
1894 + FREE_AND_NULL(array->items);
1895 array->nr = array->alloc = 0;
1896 }
1897
refs/files-backend.c
+1 -2
@@ -2944,8 +2944,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
2944 head_oid.hash, &head_type);
2945
2946 if (head_ref && !(head_type & REF_ISSYMREF)) {
2947 - free(head_ref);
2948 - head_ref = NULL;
2947 + FREE_AND_NULL(head_ref);
2948 }
2949
2950 /*
remote-testsvn.c
+1 -2
@@ -66,8 +66,7 @@ static char *read_ref_note(const unsigned char sha1[20])
66 else if (!msglen || type != OBJ_BLOB) {
67 error("Note contains unusable content. "
68 "Is something else using this notes tree? %s", notes_ref);
69 - free(msg);
70 - msg = NULL;
69 + FREE_AND_NULL(msg);
70 }
71 free_notes(NULL);
72 return msg;
sequencer.c
+1 -2
@@ -1211,8 +1211,7 @@ struct todo_list {
1211 static void todo_list_release(struct todo_list *todo_list)
1212 {
1213 strbuf_release(&todo_list->buf);
1214 - free(todo_list->items);
1215 - todo_list->items = NULL;
1214 + FREE_AND_NULL(todo_list->items);
1215 todo_list->nr = todo_list->alloc = 0;
1216 }
1217
sha1-array.c
+1 -2
@@ -35,8 +35,7 @@ int oid_array_lookup(struct oid_array *array, const struct object_id *oid)
35
36 void oid_array_clear(struct oid_array *array)
37 {
38 - free(array->oid);
39 - array->oid = NULL;
38 + FREE_AND_NULL(array->oid);
39 array->nr = 0;
40 array->alloc = 0;
41 array->sorted = 0;
sha1_file.c
+1 -2
@@ -610,8 +610,7 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
610
611 out:
612 if (seen_error) {
613 - free(ref_git);
614 - ref_git = NULL;
613 + FREE_AND_NULL(ref_git);
614 }
615
616 return ref_git;
transport-helper.c
+9 -18
@@ -242,8 +242,7 @@ static int disconnect_helper(struct transport *transport)
242 close(data->helper->out);
243 fclose(data->out);
244 res = finish_command(data->helper);
245 - free(data->helper);
246 - data->helper = NULL;
245 + FREE_AND_NULL(data->helper);
246 }
247 return res;
248 }
@@ -711,43 +710,35 @@ static int push_update_ref_status(struct strbuf *buf,
710
711 if (!strcmp(msg, "no match")) {
712 status = REF_STATUS_NONE;
714 - free(msg);
715 - msg = NULL;
713 + FREE_AND_NULL(msg);
714 }
715 else if (!strcmp(msg, "up to date")) {
716 status = REF_STATUS_UPTODATE;
719 - free(msg);
720 - msg = NULL;
717 + FREE_AND_NULL(msg);
718 }
719 else if (!strcmp(msg, "non-fast forward")) {
720 status = REF_STATUS_REJECT_NONFASTFORWARD;
724 - free(msg);
725 - msg = NULL;
721 + FREE_AND_NULL(msg);
722 }
723 else if (!strcmp(msg, "already exists")) {
724 status = REF_STATUS_REJECT_ALREADY_EXISTS;
729 - free(msg);
730 - msg = NULL;
725 + FREE_AND_NULL(msg);
726 }
727 else if (!strcmp(msg, "fetch first")) {
728 status = REF_STATUS_REJECT_FETCH_FIRST;
734 - free(msg);
735 - msg = NULL;
729 + FREE_AND_NULL(msg);
730 }
731 else if (!strcmp(msg, "needs force")) {
732 status = REF_STATUS_REJECT_NEEDS_FORCE;
739 - free(msg);
740 - msg = NULL;
733 + FREE_AND_NULL(msg);
734 }
735 else if (!strcmp(msg, "stale info")) {
736 status = REF_STATUS_REJECT_STALE;
744 - free(msg);
745 - msg = NULL;
737 + FREE_AND_NULL(msg);
738 }
739 else if (!strcmp(msg, "forced update")) {
740 forced = 1;
749 - free(msg);
750 - msg = NULL;
741 + FREE_AND_NULL(msg);
742 }
743 }
744
transport.c
+1 -2
@@ -1145,8 +1145,7 @@ void transport_unlock_pack(struct transport *transport)
1145 {
1146 if (transport->pack_lockfile) {
1147 unlink_or_warn(transport->pack_lockfile);
1148 - free(transport->pack_lockfile);
1149 - transport->pack_lockfile = NULL;
1148 + FREE_AND_NULL(transport->pack_lockfile);
1149 }
1150 }
1151
tree-diff.c
+2 -4
@@ -140,8 +140,7 @@ static struct combine_diff_path *path_appendnew(struct combine_diff_path *last,
140 /* if last->next is !NULL - it is a pre-allocated memory, we can reuse */
141 p = last->next;
142 if (p && (alloclen > (intptr_t)p->next)) {
143 - free(p);
144 - p = NULL;
143 + FREE_AND_NULL(p);
144 }
145
146 if (!p) {
@@ -559,8 +558,7 @@ struct combine_diff_path *diff_tree_paths(
558 * (see path_appendnew() for details about why)
559 */
560 if (p->next) {
562 - free(p->next);
563 - p->next = NULL;
561 + FREE_AND_NULL(p->next);
562 }
563
564 return p;
tree.c
+1 -2
@@ -226,8 +226,7 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
226
227 void free_tree_buffer(struct tree *tree)
228 {
229 - free(tree->buffer);
230 - tree->buffer = NULL;
229 + FREE_AND_NULL(tree->buffer);
230 tree->size = 0;
231 tree->object.parsed = 0;
232 }