[cairo] [PATCH 09/12] Remove useless checks for NULL before freeing

Andrea Canciani ranma42 at gmail.com
Sat Nov 12 13:20:01 PST 2011


This patch has been generated by the following Coccinelle semantic patch:

// Remove useless checks for NULL before freeing
//
// free (NULL) is a no-op, so there is no need to avoid it

@@
expression E;
@@
+ free (E);
+ E = NULL;
- if (unlikely (E != NULL)) {
-   free(E);
(
-   E = NULL;
|
-   E = 0;
)
   ...
- }

@@
expression E;
@@
+ free (E);
- if (unlikely (E != NULL)) {
-   free (E);
- }
---
 src/cairo-cogl-gradient.c |    3 +-
 src/cairo-cogl-surface.c  |   12 +++------
 test/cairo-test.c         |   59 ++++++++++++++------------------------------
 3 files changed, 24 insertions(+), 50 deletions(-)

diff --git a/src/cairo-cogl-gradient.c b/src/cairo-cogl-gradient.c
index 2dc0707..a4b9824 100644
--- a/src/cairo-cogl-gradient.c
+++ b/src/cairo-cogl-gradient.c
@@ -635,8 +635,7 @@ _cairo_cogl_get_linear_gradient (cairo_cogl_device_t *device,
     return CAIRO_INT_STATUS_SUCCESS;
 
 BAIL:
-    if (entry)
-	free (entry);
+    free (entry);
     if (gradient)
 	_cairo_cogl_linear_gradient_destroy (gradient);
     return status;
diff --git a/src/cairo-cogl-surface.c b/src/cairo-cogl-surface.c
index 0d990b3..3f9a782 100644
--- a/src/cairo-cogl-surface.c
+++ b/src/cairo-cogl-surface.c
@@ -2011,10 +2011,8 @@ _cairo_cogl_get_path_stroke_meta (cairo_cogl_surface_t *surface,
     return meta;
 
 BAIL:
-    if (meta_path)
-	free (meta_path);
-    if (meta)
-	free (meta);
+    free (meta_path);
+    free (meta);
     return NULL;
 }
 
@@ -2266,10 +2264,8 @@ _cairo_cogl_get_path_fill_meta (cairo_cogl_surface_t *surface)
     return meta;
 
 BAIL:
-    if (meta_path)
-	free (meta_path);
-    if (meta)
-	free (meta);
+    free (meta_path);
+    free (meta);
     return NULL;
 }
 
diff --git a/test/cairo-test.c b/test/cairo-test.c
index 7dda8c2..0943f67 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -228,8 +228,7 @@ cairo_test_fini (cairo_test_context_t *ctx)
 	fclose (ctx->log_file);
     ctx->log_file = NULL;
 
-    if (ctx->ref_name != NULL)
-	free (ctx->ref_name);
+    free (ctx->ref_name);
     cairo_surface_destroy (ctx->ref_image);
     cairo_surface_destroy (ctx->ref_image_flattened);
 
@@ -1387,18 +1386,11 @@ REPEAT:
     }
 
 UNWIND_CAIRO:
-    if (test_filename != NULL) {
-	free (test_filename);
-	test_filename = NULL;
-    }
-    if (fail_filename != NULL) {
-	free (fail_filename);
-	fail_filename = NULL;
-    }
-    if (pass_filename != NULL) {
-	free (pass_filename);
-	pass_filename = NULL;
-    }
+    free (test_filename);
+    free (fail_filename);
+    free (pass_filename);
+
+    test_filename = fail_filename = pass_filename = NULL;
 
 #if HAVE_MEMFAULT
     if (ret == CAIRO_TEST_FAILURE)
@@ -1442,32 +1434,19 @@ UNWIND_SURFACE:
     }
 
 UNWIND_STRINGS:
-    if (out_png_path)
-      free (out_png_path);
-    if (ref_png_path)
-      free (ref_png_path);
-    if (base_ref_png_path)
-      free (base_ref_png_path);
-    if (ref_path)
-      free (ref_path);
-    if (new_png_path)
-      free (new_png_path);
-    if (base_new_png_path)
-      free (base_new_png_path);
-    if (new_path)
-      free (new_path);
-    if (xfail_png_path)
-      free (xfail_png_path);
-    if (base_xfail_png_path)
-      free (base_xfail_png_path);
-    if (xfail_path)
-      free (xfail_path);
-    if (diff_png_path)
-      free (diff_png_path);
-    if (base_path)
-      free (base_path);
-    if (base_name)
-      free (base_name);
+    free (out_png_path);
+    free (ref_png_path);
+    free (base_ref_png_path);
+    free (ref_path);
+    free (new_png_path);
+    free (base_new_png_path);
+    free (new_path);
+    free (xfail_png_path);
+    free (base_xfail_png_path);
+    free (xfail_path);
+    free (diff_png_path);
+    free (base_path);
+    free (base_name);
 
     return ret;
 }
-- 
1.7.5.4



More information about the cairo mailing list