[PATCH] Remove more superfluous if(p) checks around free(p)

Matt Turner mattst88 at gmail.com
Wed Jun 9 08:05:47 PDT 2010


Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
 exa/exa_glyphs.c                 |   12 ++---
 hw/kdrive/ephyr/ephyrhostvideo.c |    6 +--
 hw/kdrive/ephyr/hostx.c          |   25 +++------
 hw/xfree86/modes/xf86Cursors.c   |    7 +--
 hw/xfree86/os-support/bus/Sbus.c |    6 +--
 hw/xwin/InitOutput.c             |    7 +--
 xkb/XKBGAlloc.c                  |   18 ++----
 xkb/XKBMAlloc.c                  |   18 ++----
 xkb/ddxList.c                    |    6 +--
 xkb/xkb.c                        |   21 ++++---
 xkb/xkbInit.c                    |    6 +--
 xkb/xkbUtils.c                   |  108 +++++++++++++-------------------------
 12 files changed, 84 insertions(+), 156 deletions(-)

diff --git a/exa/exa_glyphs.c b/exa/exa_glyphs.c
index b09db46..5c46ec9 100644
--- a/exa/exa_glyphs.c
+++ b/exa/exa_glyphs.c
@@ -127,15 +127,11 @@ exaUnrealizeGlyphCaches(ScreenPtr    pScreen,
 	    cache->picture = NULL;
 	}
 
-	if (cache->hashEntries) {
-	    free(cache->hashEntries);
-	    cache->hashEntries = NULL;
-	}
+	free(cache->hashEntries);
+	cache->hashEntries = NULL;
 	
-	if (cache->glyphs) {
-	    free(cache->glyphs);
-	    cache->glyphs = NULL;
-	}
+	free(cache->glyphs);
+	cache->glyphs = NULL;
 	cache->glyphCount = 0;
     }
 }
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 38927b0..9dde768 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -831,10 +831,8 @@ out:
         XFreeGC (dpy, gc) ;
         gc = NULL ;
     }
-    if (rects) {
-        free (rects) ;
-        rects = NULL ;
-    }
+    free(rects);
+    rects = NULL;
     EPHYR_LOG ("leave\n") ;
     return is_ok ;
 }
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index d546370..c960189 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -669,11 +669,8 @@ hostx_screen_init (EphyrScreenInfo screen,
 	}
       else
 	{
-	  if (host_screen->ximg->data) 
-	    {
-	      free(host_screen->ximg->data);
-	      host_screen->ximg->data = NULL;
-	    } 
+	  free(host_screen->ximg->data);
+	  host_screen->ximg->data = NULL; 
 
 	  XDestroyImage(host_screen->ximg);
 	}
@@ -1160,10 +1157,8 @@ out:
         XFree (visuals) ;
         visuals = NULL;
     }
-    if (host_visuals) {
-        free (host_visuals) ;
-        host_visuals = NULL;
-    }
+    free(host_visuals);
+    host_visuals = NULL;
     EPHYR_LOG ("leave\n") ;
     return is_ok ;
 
@@ -1292,10 +1287,8 @@ hostx_set_window_bounding_rectangles (int a_window,
                              rects, a_num_rects, ShapeSet, YXBanded) ;
     is_ok = TRUE ;
 
-    if (rects) {
-        free (rects) ;
-        rects = NULL ;
-    }
+    free(rects);
+    rects = NULL;
     EPHYR_LOG ("leave\n") ;
     return is_ok;
 }
@@ -1329,10 +1322,8 @@ hostx_set_window_clipping_rectangles (int a_window,
                              rects, a_num_rects, ShapeSet, YXBanded) ;
     is_ok = TRUE ;
 
-    if (rects) {
-        free (rects) ;
-        rects = NULL ;
-    }
+    free(rects);
+    rects = NULL;
     EPHYR_LOG ("leave\n") ;
     return is_ok;
 }
diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c
index 5842a61..038f1c8 100644
--- a/hw/xfree86/modes/xf86Cursors.c
+++ b/hw/xfree86/modes/xf86Cursors.c
@@ -659,11 +659,8 @@ xf86_cursors_fini (ScreenPtr screen)
 	xf86DestroyCursorInfoRec (xf86_config->cursor_info);
 	xf86_config->cursor_info = NULL;
     }
-    if (xf86_config->cursor_image)
-    {
-	free(xf86_config->cursor_image);
-	xf86_config->cursor_image = NULL;
-    }
+    free(xf86_config->cursor_image);
+    xf86_config->cursor_image = NULL;
     if (xf86_config->cursor)
     {
 	FreeCursor (xf86_config->cursor, None);
diff --git a/hw/xfree86/os-support/bus/Sbus.c b/hw/xfree86/os-support/bus/Sbus.c
index 9ccc289..7829d80 100644
--- a/hw/xfree86/os-support/bus/Sbus.c
+++ b/hw/xfree86/os-support/bus/Sbus.c
@@ -191,10 +191,8 @@ sparcPromClose(void)
 	close(promFd);
 	promFd = -1;
     }
-    if (promOpio) {
-	free(promOpio);
-	promOpio = NULL;
-    }
+    free(promOpio);
+    promOpio = NULL;
     promOpenCount = 0;
 }
 
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index 1ab059f..c37733d 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -275,11 +275,8 @@ ddxGiveUp (void)
     }
   
   /* Free concatenated command line */
-  if (g_pszCommandLine)
-    {
-      free (g_pszCommandLine);
-      g_pszCommandLine = NULL;
-    }
+  free(g_pszCommandLine);
+  g_pszCommandLine = NULL;
 
   /* Remove our keyboard hook if it is installed */
   winRemoveKeyboardHookLL ();
diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c
index 7a3659f..2e4808a 100644
--- a/xkb/XKBGAlloc.c
+++ b/xkb/XKBGAlloc.c
@@ -114,10 +114,8 @@ register char *ptr;
     }
     if (freeAll) {
 	(*num_inout)= (*sz_inout)= 0;
-	if (*elems) {
-	    free(*elems);
-	    *elems= NULL;
-	}
+	free(*elems);
+	*elems = NULL;
     }
     else if (first+count>=(*num_inout))
 	*num_inout= first;
@@ -137,14 +135,10 @@ _XkbClearProperty(char *prop_in)
 {
 XkbPropertyPtr	prop= (XkbPropertyPtr)prop_in;
 
-    if (prop->name) {
-	free(prop->name);
-	prop->name= NULL;
-    }
-    if (prop->value) {
-	free(prop->value);
-	prop->value= NULL;
-    }
+    free(prop->name);
+    prop->name = NULL;
+    free(prop->value);
+    prop->value = NULL;
     return;
 }
 
diff --git a/xkb/XKBMAlloc.c b/xkb/XKBMAlloc.c
index 27151b8..c3b633e 100644
--- a/xkb/XKBMAlloc.c
+++ b/xkb/XKBMAlloc.c
@@ -221,18 +221,12 @@ XkbCopyKeyType(XkbKeyTypePtr from,XkbKeyTypePtr into)
 {
     if ((!from)||(!into))
 	return BadMatch;
-    if (into->map) {
-	free(into->map);
-	into->map= NULL;
-    }
-    if (into->preserve) {
-	free(into->preserve);
-	into->preserve= NULL;
-    }
-    if (into->level_names) {
-	free(into->level_names);
-	into->level_names= NULL;
-    }
+    free(into->map);
+    into->map = NULL;
+    free(into->preserve);
+    into->preserve = NULL;
+    free(into->level_names);
+    into->level_names = NULL;
     *into= *from;
     if ((from->map)&&(into->map_count>0)) {
 	into->map= calloc(into->map_count, sizeof(XkbKTMapEntryRec));
diff --git a/xkb/ddxList.c b/xkb/ddxList.c
index eee3887..f2701ba 100644
--- a/xkb/ddxList.c
+++ b/xkb/ddxList.c
@@ -208,10 +208,8 @@ char	tmpname[PATH_MAX];
 	return BadImplementation;
     }
     list->nFound[what]= 0;
-    if (buf) {
-        free(buf);
-        buf = NULL;
-    }
+    free(buf);
+    buf = NULL;
     buf = malloc(PATH_MAX * sizeof(char));
     if (!buf)
         return BadAlloc;
diff --git a/xkb/xkb.c b/xkb/xkb.c
index 5a425bd..046e8da 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -5510,10 +5510,8 @@ ProcXkbListComponents(ClientPtr client)
     if ((XkbPaddedSize(len)/4)!=stuff->length)
 	return BadLength;
     if ((status=XkbDDXList(dev,&list,client))!=Success) {
-	if (list.pool) {
-	    free(list.pool);
-	    list.pool= NULL;
-	}
+	free(list.pool);
+	list.pool = NULL;
 	return status;
     }
     bzero(&rep,sizeof(xkbListComponentsReply));
@@ -5886,11 +5884,16 @@ ProcXkbGetKbdByName(ClientPtr client)
 	XkbFreeKeyboard(new,XkbAllComponentsMask,TRUE);
 	new= NULL;
     }
-    if (names.keycodes)	{ free(names.keycodes); names.keycodes= NULL; }
-    if (names.types)	{ free(names.types); names.types= NULL; }
-    if (names.compat)	{ free(names.compat); names.compat= NULL; }
-    if (names.symbols)	{ free(names.symbols); names.symbols= NULL; }
-    if (names.geometry)	{ free(names.geometry); names.geometry= NULL; }
+    free(names.keycodes);
+    names.keycodes = NULL;
+    free(names.types);
+    names.types = NULL;
+    free(names.compat);
+    names.compat = NULL;
+    free(names.symbols);
+    names.symbols = NULL;
+    free(names.geometry);
+    names.geometry = NULL;
     return Success;
 }
 
diff --git a/xkb/xkbInit.c b/xkb/xkbInit.c
index 0f3ffa4..2ac1d6d 100644
--- a/xkb/xkbInit.c
+++ b/xkb/xkbInit.c
@@ -645,10 +645,8 @@ unwind_key:
 void
 XkbFreeInfo(XkbSrvInfoPtr xkbi)
 {
-    if (xkbi->radioGroups) {
-	free(xkbi->radioGroups);
-	xkbi->radioGroups= NULL;
-    }
+    free(xkbi->radioGroups);
+    xkbi->radioGroups = NULL;
     if (xkbi->mouseKeyTimer) {
 	TimerFree(xkbi->mouseKeyTimer);
 	xkbi->mouseKeyTimer= NULL;
diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index 0766922..1b1a78a 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -933,10 +933,8 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
                    src->map->size_syms * sizeof(KeySym));
         }
         else {
-            if (dst->map->syms) {
-                free(dst->map->syms);
-                dst->map->syms = NULL;
-            }
+            free(dst->map->syms);
+            dst->map->syms = NULL;
         }
         dst->map->num_syms = src->map->num_syms;
         dst->map->size_syms = src->map->size_syms;
@@ -958,10 +956,8 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
                    (src->max_key_code + 1) * sizeof(XkbSymMapRec));
         }
         else {
-            if (dst->map->key_sym_map) {
-                free(dst->map->key_sym_map);
-                dst->map->key_sym_map = NULL;
-            }
+            free(dst->map->key_sym_map);
+            dst->map->key_sym_map = NULL;
         }
 
         if (src->map->types && src->map->num_types) {
@@ -1144,10 +1140,8 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
             memcpy(dst->map->modmap, src->map->modmap, src->max_key_code + 1);
         }
         else {
-            if (dst->map->modmap) {
-                free(dst->map->modmap);
-                dst->map->modmap = NULL;
-            }
+            free(dst->map->modmap);
+            dst->map->modmap = NULL;
         }
     }
     else {
@@ -1186,10 +1180,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
                    src->max_key_code + 1);
         }
         else {
-            if (dst->server->explicit) {
-                free(dst->server->explicit);
-                dst->server->explicit = NULL;
-            }
+            free(dst->server->explicit);
+            dst->server->explicit = NULL;
         }
 
         if (src->server->acts) {
@@ -1207,10 +1199,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
                    src->server->size_acts * sizeof(XkbAction));
         }
         else {
-            if (dst->server->acts) {
-                free(dst->server->acts);
-                dst->server->acts = NULL;
-            }
+            free(dst->server->acts);
+            dst->server->acts = NULL;
         }
        dst->server->size_acts = src->server->size_acts;
        dst->server->num_acts = src->server->num_acts;
@@ -1232,10 +1222,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
                    (src->max_key_code + 1) * sizeof(unsigned short));
         }
         else {
-            if (dst->server->key_acts) {
-                free(dst->server->key_acts);
-                dst->server->key_acts = NULL;
-            }
+            free(dst->server->key_acts);
+            dst->server->key_acts = NULL;
         }
 
         if (src->server->behaviors) {
@@ -1255,10 +1243,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
                    (src->max_key_code + 1) * sizeof(XkbBehavior));
         }
         else {
-            if (dst->server->behaviors) {
-                free(dst->server->behaviors);
-                dst->server->behaviors = NULL;
-            }
+            free(dst->server->behaviors);
+            dst->server->behaviors = NULL;
         }
 
         memcpy(dst->server->vmods, src->server->vmods, XkbNumVirtualMods);
@@ -1280,10 +1266,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
                    (src->max_key_code + 1) * sizeof(unsigned short));
         }
         else {
-            if (dst->server->vmodmap) {
-                free(dst->server->vmodmap);
-                dst->server->vmodmap = NULL;
-            }
+            free(dst->server->vmodmap);
+            dst->server->vmodmap = NULL;
         }
     }
     else {
@@ -1323,10 +1307,8 @@ _XkbCopyNames(XkbDescPtr src, XkbDescPtr dst)
                    (src->max_key_code + 1) * sizeof(XkbKeyNameRec));
         }
         else {
-            if (dst->names->keys) {
-                free(dst->names->keys);
-                dst->names->keys = NULL;
-            }
+            free(dst->names->keys);
+            dst->names->keys = NULL;
         }
 
         if (src->names->num_key_aliases) {
@@ -1346,10 +1328,8 @@ _XkbCopyNames(XkbDescPtr src, XkbDescPtr dst)
                    src->names->num_key_aliases * sizeof(XkbKeyAliasRec));
         }
         else {
-            if (dst->names->key_aliases) {
-                free(dst->names->key_aliases);
-                dst->names->key_aliases = NULL;
-            }
+            free(dst->names->key_aliases);
+            dst->names->key_aliases = NULL;
         }
         dst->names->num_key_aliases = src->names->num_key_aliases;
 
@@ -1750,20 +1730,14 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
                      j < dsection->num_doodads;
                      j++, ddoodad++) {
                     if (ddoodad->any.type == XkbTextDoodad) {
-                        if (ddoodad->text.text) {
-                            free(ddoodad->text.text);
-                            ddoodad->text.text = NULL;
-                        }
-                        if (ddoodad->text.font) {
-                            free(ddoodad->text.font);
-                            ddoodad->text.font = NULL;
-                        }
+                        free(ddoodad->text.text);
+                        ddoodad->text.text = NULL;
+                        free(ddoodad->text.font);
+                        ddoodad->text.font = NULL;
                      }
                      else if (ddoodad->any.type == XkbLogoDoodad) {
-                        if (ddoodad->logo.logo_name) {
-                            free(ddoodad->logo.logo_name);
-                            ddoodad->logo.logo_name = NULL;
-                        }
+                        free(ddoodad->logo.logo_name);
+                        ddoodad->logo.logo_name = NULL;
                     }
                 }
 
@@ -1877,20 +1851,14 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
                  i < dst->geom->num_doodads;
                  i++, ddoodad++) {
                  if (ddoodad->any.type == XkbTextDoodad) {
-                    if (ddoodad->text.text) {
-                        free(ddoodad->text.text);
-                        ddoodad->text.text = NULL;
-                    }
-                    if (ddoodad->text.font) {
-                        free(ddoodad->text.font);
-                        ddoodad->text.font = NULL;
-                    }
+                    free(ddoodad->text.text);
+                    ddoodad->text.text = NULL;
+                    free(ddoodad->text.font);
+                    ddoodad->text.font = NULL;
                  }
                  else if (ddoodad->any.type == XkbLogoDoodad) {
-                    if (ddoodad->logo.logo_name) {
-                        free(ddoodad->logo.logo_name);
-                        ddoodad->logo.logo_name = NULL;
-                    }
+                    free(ddoodad->logo.logo_name);
+                    ddoodad->logo.logo_name = NULL;
                 }
             }
             dst->geom->num_doodads = 0;
@@ -2035,10 +2003,8 @@ _XkbCopyIndicators(XkbDescPtr src, XkbDescPtr dst)
         memcpy(dst->indicators, src->indicators, sizeof(XkbIndicatorRec));
     }
     else {
-        if (dst->indicators) {
-            free(dst->indicators);
-            dst->indicators = NULL;
-        }
+        free(dst->indicators);
+        dst->indicators = NULL;
     }
     return TRUE;
 }
@@ -2056,10 +2022,8 @@ _XkbCopyControls(XkbDescPtr src, XkbDescPtr dst)
         memcpy(dst->ctrls, src->ctrls, sizeof(XkbControlsRec));
     }
     else {
-        if (dst->ctrls) {
-            free(dst->ctrls);
-            dst->ctrls = NULL;
-        }
+        free(dst->ctrls);
+        dst->ctrls = NULL;
     }
     return TRUE;
 }
-- 
1.6.4.4



More information about the xorg-devel mailing list