refactor various if (x) FREE_AND_NULL(x) to just FREE_AND_NULL(x)
Change the few conditional uses of FREE_AND_NULL(x) to be unconditional. As noted in the standard[1] free(NULL) is perfectly valid, so we might as well leave this check up to the C library. 1. http://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Aug 17, 2018 at 13:02 UTC
ce528de023f82d767096b0342b6da8039feff7bc
4 files changed
+4
-12
blame.c
+1
-3
@@ -313,9 +313,7 @@ static void fill_origin_blob(struct diff_options *opt,
313
314
static void drop_origin_blob(struct blame_origin *o)
315
{
316
- if (o->file.ptr) {
317
- FREE_AND_NULL(o->file.ptr);
318
- }
316
+ FREE_AND_NULL(o->file.ptr);
317
}
318
319
/*
branch.c
+1
-3
@@ -25,9 +25,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
25
tracking->remote = remote->name;
26
} else {
27
free(tracking->spec.src);
28
- if (tracking->src) {
29
- FREE_AND_NULL(tracking->src);
30
- }
28
+ FREE_AND_NULL(tracking->src);
29
}
30
tracking->spec.src = NULL;
31
}
http.c
+1
-3
@@ -2418,9 +2418,7 @@ void release_http_object_request(struct http_object_request *freq)
2418
close(freq->localfile);
2419
freq->localfile = -1;
2420
}
2421
- if (freq->url != NULL) {
2422
- FREE_AND_NULL(freq->url);
2423
- }
2421
+ FREE_AND_NULL(freq->url);
2422
if (freq->slot != NULL) {
2423
freq->slot->callback_func = NULL;
2424
freq->slot->callback_data = NULL;
tree-diff.c
+1
-3
@@ -557,9 +557,7 @@ struct combine_diff_path *diff_tree_paths(
557
* free pre-allocated last element, if any
558
* (see path_appendnew() for details about why)
559
*/
560
- if (p->next) {
561
- FREE_AND_NULL(p->next);
562
- }
560
+ FREE_AND_NULL(p->next);
561
562
return p;
563
}