[PATCH] Remove superfluous if(p!=NULL) checks around free(p); p=NULL; p_foo=0;

Cyril Brulebois kibi at debian.org
Wed Nov 10 07:45:52 PST 2010


This patch has been prepared with the following Coccinelle semantic patch:

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

The remaining bits in “...” were then checked, and when it was about a
number of, a size of, or a count of E, the substitution was considered
healthy.

Signed-off-by: Cyril Brulebois <kibi at debian.org>
---
 hw/kdrive/ephyr/ephyrvideo.c    |    8 +++-----
 miext/rootless/rootlessScreen.c |    8 +++-----
 xkb/xkb.c                       |    4 ++--
 3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index 69a89ae..e69f86e 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -982,11 +982,9 @@ ephyrPutImage (KdScreenInfo *a_info,
         }
     }
     if (!is_ok) {
-        if (port_priv->image_buf) {
-            free (port_priv->image_buf) ;
-            port_priv->image_buf = NULL ;
-            port_priv->image_buf_size = 0 ;
-        }
+        free(port_priv->image_buf);
+        port_priv->image_buf = NULL;
+        port_priv->image_buf_size = 0 ;
     }
 
     result = Success ;
diff --git a/miext/rootless/rootlessScreen.c b/miext/rootless/rootlessScreen.c
index 61d2f5d..408788e 100644
--- a/miext/rootless/rootlessScreen.c
+++ b/miext/rootless/rootlessScreen.c
@@ -150,11 +150,9 @@ RootlessCloseScreen(int i, ScreenPtr pScreen)
     // fixme unwrap everything that was wrapped?
     pScreen->CloseScreen = s->CloseScreen;
 
-    if (s->pixmap_data != NULL) {
-        free(s->pixmap_data);
-        s->pixmap_data = NULL;
-        s->pixmap_data_size = 0;
-    }
+    free(s->pixmap_data);
+    s->pixmap_data = NULL;
+    s->pixmap_data_size = 0;
 
     free(s);
     return pScreen->CloseScreen(i, pScreen);
diff --git a/xkb/xkb.c b/xkb/xkb.c
index bbb1d9d..7331318 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -4124,7 +4124,7 @@ _XkbSetNames(ClientPtr client, DeviceIntPtr dev, xkbSetNamesReq *stuff)
                     stuff->nKeyAliases*sizeof(XkbKeyAliasRec));
             tmp+= stuff->nKeyAliases*2;
         }
-        else if (names->key_aliases!=NULL) {
+        else {
             free(names->key_aliases);
             names->key_aliases= NULL;
             names->num_key_aliases= 0;
@@ -4143,7 +4143,7 @@ _XkbSetNames(ClientPtr client, DeviceIntPtr dev, xkbSetNamesReq *stuff)
             }
             tmp+= stuff->nRadioGroups;
         }
-        else if (names->radio_groups) {
+        else {
             free(names->radio_groups);
             names->radio_groups= NULL;
             names->num_rg= 0;
-- 
1.7.2.3



More information about the xorg-devel mailing list