[Pixman] [PATCH 1/5] Remove useless checks for NULL before freeing

Andrea Canciani ranma42 at gmail.com
Fri Nov 4 05:23:25 PDT 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);
- }
---
 pixman/pixman-image.c  |    7 ++-----
 pixman/pixman-region.c |    9 +++------
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/pixman/pixman-image.c b/pixman/pixman-image.c
index 09d7cbc..913853c 100644
--- a/pixman/pixman-image.c
+++ b/pixman/pixman-image.c
@@ -145,11 +145,8 @@ _pixman_image_fini (pixman_image_t *image)
 
 	pixman_region32_fini (&common->clip_region);
 
-	if (common->transform)
-	    free (common->transform);
-
-	if (common->filter_params)
-	    free (common->filter_params);
+	free (common->transform);
+	free (common->filter_params);
 
 	if (common->alpha_map)
 	    pixman_image_unref ((pixman_image_t *)common->alpha_map);
diff --git a/pixman/pixman-region.c b/pixman/pixman-region.c
index 47beb52..80219c6 100644
--- a/pixman/pixman-region.c
+++ b/pixman/pixman-region.c
@@ -828,8 +828,7 @@ pixman_op (region_type_t *  new_reg,               /* Place to store result
     {
         if (!pixman_rect_alloc (new_reg, new_size))
         {
-            if (old_data)
-		free (old_data);
+            free (old_data);
             return FALSE;
 	}
     }
@@ -1005,8 +1004,7 @@ pixman_op (region_type_t *  new_reg,               /* Place to store result
         APPEND_REGIONS (new_reg, r2_band_end, r2_end);
     }
 
-    if (old_data)
-	free (old_data);
+    free (old_data);
 
     if (!(numRects = new_reg->data->numRects))
     {
@@ -1027,8 +1025,7 @@ pixman_op (region_type_t *  new_reg,               /* Place to store result
     return TRUE;
 
 bail:
-    if (old_data)
-	free (old_data);
+    free (old_data);
 
     return pixman_break (new_reg);
 }
-- 
1.7.5.4



More information about the Pixman mailing list