@matheusbsbs / matheus-bagliano / commits / 4cac42b132
Fork 0

free(NULL) is perfectly valid.

Jonas noticed some places say "if (X) free(X)" which is totally unnecessary. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Aug 27, 2006 at 21:19 UTC 4cac42b1324951579036a9d3ac403f5c2c3eeed8
10 files changed +21 -44
builtin-apply.c
+2 -4
@@ -1131,8 +1131,7 @@ static struct fragment *parse_binary_hunk(char **buf_p,
1131 return frag;
1132
1133 corrupt:
1134 - if (data)
1135 - free(data);
1134 + free(data);
1135 *status_p = -1;
1136 error("corrupt binary patch at line %d: %.*s",
1137 linenr-1, llen-1, buffer);
@@ -1329,8 +1328,7 @@ static void show_stats(struct patch *patch)
1328 printf(" %s%-*s |%5d %.*s%.*s\n", prefix,
1329 len, name, patch->lines_added + patch->lines_deleted,
1330 add, pluses, del, minuses);
1332 - if (qname)
1333 - free(qname);
1331 + free(qname);
1332 }
1333
1334 static int read_old_data(struct stat *st, const char *path, void *buf, unsigned long size)
builtin-fmt-merge-msg.c
+1 -2
@@ -55,8 +55,7 @@ static void free_list(struct list *list)
55
56 for (i = 0; i < list->nr; i++) {
57 free(list->list[i]);
58 - if (list->payload[i])
59 - free(list->payload[i]);
58 + free(list->payload[i]);
59 }
60 free(list->list);
61 free(list->payload);
builtin-repo-config.c
+2 -4
@@ -122,10 +122,8 @@ static int get_value(const char* key_, const char* regex_)
122 ret = (seen == 1) ? 0 : 1;
123
124 free_strings:
125 - if (repo_config)
126 - free(repo_config);
127 - if (global)
128 - free(global);
125 + free(repo_config);
126 + free(global);
127 return ret;
128 }
129
builtin-rev-list.c
+2 -4
@@ -93,10 +93,8 @@ static void show_commit(struct commit *commit)
93 free_commit_list(commit->parents);
94 commit->parents = NULL;
95 }
96 - if (commit->buffer) {
97 - free(commit->buffer);
98 - commit->buffer = NULL;
99 - }
96 + free(commit->buffer);
97 + commit->buffer = NULL;
98 }
99
100 static void process_blob(struct blob *blob,
config.c
+2 -4
@@ -361,8 +361,7 @@ int git_config(config_fn_t fn)
361 }
362
363 ret += git_config_from_file(fn, filename);
364 - if (repo_config)
365 - free(repo_config);
364 + free(repo_config);
365 return ret;
366 }
367
@@ -734,8 +733,7 @@ int git_config_set_multivar(const char* key, const char* value,
733 out_free:
734 if (0 <= fd)
735 close(fd);
737 - if (config_filename)
738 - free(config_filename);
736 + free(config_filename);
737 if (lock_file) {
738 unlink(lock_file);
739 free(lock_file);
fetch.c
+1 -2
@@ -302,8 +302,7 @@ int pull(int targets, char **target, const char **write_ref,
302 if (ret)
303 goto unlock_and_fail;
304 }
305 - if (msg)
306 - free(msg);
305 + free(msg);
306
307 return 0;
308
http-fetch.c
+4 -9
@@ -696,10 +696,8 @@ xml_start_tag(void *userData, const char *name, const char **atts)
696 strcat(ctx->name, ".");
697 strcat(ctx->name, c);
698
699 - if (ctx->cdata) {
700 - free(ctx->cdata);
701 - ctx->cdata = NULL;
702 - }
699 + free(ctx->cdata);
700 + ctx->cdata = NULL;
701
702 ctx->userFunc(ctx, 0);
703 }
@@ -726,8 +724,7 @@ static void
724 xml_cdata(void *userData, const XML_Char *s, int len)
725 {
726 struct xml_ctx *ctx = (struct xml_ctx *)userData;
729 - if (ctx->cdata)
730 - free(ctx->cdata);
727 + free(ctx->cdata);
728 ctx->cdata = xmalloc(len + 1);
729 strlcpy(ctx->cdata, s, len + 1);
730 }
@@ -765,9 +762,7 @@ static void handle_remote_ls_ctx(struct xml_ctx *ctx, int tag_closed)
762 ls->dentry_flags |= IS_DIR;
763 }
764 } else if (!strcmp(ctx->name, DAV_PROPFIND_RESP)) {
768 - if (ls->dentry_name) {
769 - free(ls->dentry_name);
770 - }
765 + free(ls->dentry_name);
766 ls->dentry_name = NULL;
767 ls->dentry_flags = 0;
768 }
http-push.c
+4 -9
@@ -1238,10 +1238,8 @@ xml_start_tag(void *userData, const char *name, const char **atts)
1238 strcat(ctx->name, ".");
1239 strcat(ctx->name, c);
1240
1241 - if (ctx->cdata) {
1242 - free(ctx->cdata);
1243 - ctx->cdata = NULL;
1244 - }
1241 + free(ctx->cdata);
1242 + ctx->cdata = NULL;
1243
1244 ctx->userFunc(ctx, 0);
1245 }
@@ -1268,8 +1266,7 @@ static void
1266 xml_cdata(void *userData, const XML_Char *s, int len)
1267 {
1268 struct xml_ctx *ctx = (struct xml_ctx *)userData;
1271 - if (ctx->cdata)
1272 - free(ctx->cdata);
1269 + free(ctx->cdata);
1270 ctx->cdata = xmalloc(len + 1);
1271 strlcpy(ctx->cdata, s, len + 1);
1272 }
@@ -1518,9 +1515,7 @@ static void handle_remote_ls_ctx(struct xml_ctx *ctx, int tag_closed)
1515 ls->dentry_flags |= IS_DIR;
1516 }
1517 } else if (!strcmp(ctx->name, DAV_PROPFIND_RESP)) {
1521 - if (ls->dentry_name) {
1522 - free(ls->dentry_name);
1523 - }
1518 + free(ls->dentry_name);
1519 ls->dentry_name = NULL;
1520 ls->dentry_flags = 0;
1521 }
path-list.c
+1 -2
@@ -85,8 +85,7 @@ void path_list_clear(struct path_list *list, int free_items)
85 for (i = 0; i < list->nr; i++) {
86 if (list->strdup_paths)
87 free(list->items[i].path);
88 - if (list->items[i].util)
89 - free(list->items[i].util);
88 + free(list->items[i].util);
89 }
90 free(list->items);
91 }
refs.c
+2 -4
@@ -348,10 +348,8 @@ void unlock_ref(struct ref_lock *lock)
348 if (lock->lk)
349 rollback_lock_file(lock->lk);
350 }
351 - if (lock->ref_file)
352 - free(lock->ref_file);
353 - if (lock->log_file)
354 - free(lock->log_file);
351 + free(lock->ref_file);
352 + free(lock->log_file);
353 free(lock);
354 }
355