refactor various if (x) FREE_AND_NULL(x) to just FREE_AND_NULL(x)
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 17 Aug 2018 13:02:50 +0000 (13:02 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Aug 2018 17:08:56 +0000 (10:08 -0700)
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>
blame.c
branch.c
http.c
tree-diff.c
diff --git a/blame.c b/blame.c
index 14d0e0b5751c2abaad16dac81a71436ca29ddde4..f9b7f0a0de57335ce2d6cb82818401878c8c0fd6 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -313,9 +313,7 @@ static void fill_origin_blob(struct diff_options *opt,
 
 static void drop_origin_blob(struct blame_origin *o)
 {
-       if (o->file.ptr) {
-               FREE_AND_NULL(o->file.ptr);
-       }
+       FREE_AND_NULL(o->file.ptr);
 }
 
 /*
index f967c98f6324c49d9ab7f94f973230512af13707..a2c9623d1d002963f040f0fe51cdd22c2f7d8e25 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -25,9 +25,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
                        tracking->remote = remote->name;
                } else {
                        free(tracking->spec.src);
-                       if (tracking->src) {
-                               FREE_AND_NULL(tracking->src);
-                       }
+                       FREE_AND_NULL(tracking->src);
                }
                tracking->spec.src = NULL;
        }
diff --git a/http.c b/http.c
index b4bfbceaeb7e58e79cac17f8768a7e36cff3405e..4162860ee316365091ac3978a83d2311682b8079 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2418,9 +2418,7 @@ void release_http_object_request(struct http_object_request *freq)
                close(freq->localfile);
                freq->localfile = -1;
        }
-       if (freq->url != NULL) {
-               FREE_AND_NULL(freq->url);
-       }
+       FREE_AND_NULL(freq->url);
        if (freq->slot != NULL) {
                freq->slot->callback_func = NULL;
                freq->slot->callback_data = NULL;
index fe2e466ac1dcb164b214ce4856ed9d62884ddbd3..553bc0e63ae37ada1c3e19ae748d1228561f00f6 100644 (file)
@@ -557,9 +557,7 @@ struct combine_diff_path *diff_tree_paths(
         * free pre-allocated last element, if any
         * (see path_appendnew() for details about why)
         */
-       if (p->next) {
-               FREE_AND_NULL(p->next);
-       }
+       FREE_AND_NULL(p->next);
 
        return p;
 }