[PATCH] libX11 fix:redundant null checks

walter harms wharms at bfs.de
Thu Jun 5 09:37:40 PDT 2014


 This patch removes some redundant null checks before free
 it should not chance the code otherwise. Be aware that this
 is only the frist series.

Signed-off-by: Harms <wharms at bfs,de>
---
 src/FetchName.c  |  4 ++--
 src/Font.c       | 22 +++++++++++-----------
 src/FontInfo.c   |  4 ++--
 src/FontNames.c  |  4 ++--
 src/GetFPath.c   |  4 ++--
 src/GetHints.c   | 16 ++++++++--------
 src/GetNrmHint.c |  3 +--
 src/GetRGBCMap.c |  8 ++++----
 src/GetStCmap.c  |  2 +-
 src/GetWMCMapW.c |  2 +-
 src/ImUtil.c     |  4 ++--
 src/InitExt.c    |  2 +-
 src/KeyBind.c    |  9 +++++----
 src/ListExt.c    |  4 ++--
 src/ModMap.c     |  5 ++---
 src/OpenDis.c    | 34 +++++++++++++---------------------
 src/PutImage.c   | 15 ++++++---------
 src/RdBitF.c     |  2 +-
 src/ScrResStr.c  |  3 +--
 src/StBytes.c    |  2 +-
 src/XlibInt.c    | 12 ++++++------
 21 files changed, 78 insertions(+), 87 deletions(-)

diff --git a/src/FetchName.c b/src/FetchName.c
index 8605a6d..160eb5b 100644
--- a/src/FetchName.c
+++ b/src/FetchName.c
@@ -58,7 +58,7 @@ Status XFetchName (
 	*name = (char *)data;
 	return(1);
 	}
-    if (data) Xfree (data);
+    Xfree (data);
     *name = NULL;
     return(0);
 }
@@ -89,7 +89,7 @@ Status XGetIconName (
 	*icon_name = (char*)data;
 	return(1);
 	}
-    if (data) Xfree (data);
+    Xfree (data);
     *icon_name = NULL;
     return(0);
 }
diff --git a/src/Font.c b/src/Font.c
index 6fadd58..650bc6f 100644
--- a/src/Font.c
+++ b/src/Font.c
@@ -170,8 +170,8 @@ XFreeFont(
 #endif
     }
     _XFreeExtData(fs->ext_data);
-    if (fs->properties)
-	Xfree (fs->properties);
+
+    Xfree (fs->properties);
     Xfree (fs);
     return 1;
 }
@@ -271,7 +271,7 @@ _XQueryFont (
 	    }
 	}
 	if (! fs->per_char) {
-	    if (fs->properties) Xfree(fs->properties);
+	    Xfree(fs->properties);
 	    Xfree(fs);
 	    _XEatDataWords(dpy, reply_left);
 	    return (XFontStruct *)NULL;
@@ -524,14 +524,14 @@ _XF86BigfontQueryFont (
 	             + (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16);
 	    pUniqCI = Xmalloc (nbytes);
 	    if (!pUniqCI) {
-		if (fs->properties) Xfree(fs->properties);
+		Xfree(fs->properties);
 		Xfree(fs);
 		_XEatDataWords(dpy, reply_left);
 		return (XFontStruct *)NULL;
 	    }
 	    if (! (fs->per_char = Xmalloc (reply.nCharInfos * sizeof(XCharStruct)))) {
 		Xfree(pUniqCI);
-		if (fs->properties) Xfree(fs->properties);
+		Xfree(fs->properties);
 		Xfree(fs);
 		_XEatDataWords(dpy, reply_left);
 		return (XFontStruct *)NULL;
@@ -542,7 +542,7 @@ _XF86BigfontQueryFont (
 		if (pIndex2UniqIndex[i] >= reply.nUniqCharInfos) {
 		    fprintf(stderr, "_XF86BigfontQueryFont: server returned wrong data\n");
 		    Xfree(pUniqCI);
-		    if (fs->properties) Xfree(fs->properties);
+		    Xfree(fs->properties);
 		    Xfree(fs);
 		    return (XFontStruct *)NULL;
 		}
@@ -558,7 +558,7 @@ _XF86BigfontQueryFont (

 	    pData = Xmalloc(sizeof(XExtData));
 	    if (!pData) {
-		if (fs->properties) Xfree(fs->properties);
+		Xfree(fs->properties);
 		Xfree(fs);
 		return (XFontStruct *)NULL;
 	    }
@@ -578,7 +578,7 @@ _XF86BigfontQueryFont (
 		if (extcodes->serverCapabilities & CAP_VerifiedLocal)
 		    fprintf(stderr, "_XF86BigfontQueryFont: could not attach shm segment\n");
 	        Xfree(pData);
-	        if (fs->properties) Xfree(fs->properties);
+	        Xfree(fs->properties);
 	        Xfree(fs);
 		/* Stop requesting shared memory transport from now on. */
 		extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm;
@@ -593,7 +593,7 @@ _XF86BigfontQueryFont (
 		      && *(CARD32 *)(addr + reply.shmsegoffset + reply.nCharInfos * sizeof(XCharStruct)) == extcodes->serverSignature)) {
 		    shmdt(addr);
 		    Xfree(pData);
-		    if (fs->properties) Xfree(fs->properties);
+		    Xfree(fs->properties);
 		    Xfree(fs);
 		    /* Stop requesting shared memory transport from now on. */
 		    extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm;
@@ -697,8 +697,8 @@ int _XF86LoadQueryLocaleFont(
 #endif
 	}
 	_XFreeExtData(fs->ext_data);
-	if (fs->properties)
-	    Xfree (fs->properties);
+
+	Xfree (fs->properties);
 	*fidp = fs->fid;
 	Xfree (fs);
     } else {
diff --git a/src/FontInfo.c b/src/FontInfo.c
index 763aafb..a2d12c2 100644
--- a/src/FontInfo.c
+++ b/src/FontInfo.c
@@ -179,8 +179,8 @@ XFontStruct **info)	/* RETURN */
         Xfree(flist[j]);
         if (finfo[j].properties) Xfree(finfo[j].properties);
     }
-    if (flist) Xfree(flist);
-    if (finfo) Xfree(finfo);
+    Xfree(flist);
+    Xfree(finfo);

   clearwire:
     /* Clear the wire. */
diff --git a/src/FontNames.c b/src/FontNames.c
index c50de2e..6fc6b12 100644
--- a/src/FontNames.c
+++ b/src/FontNames.c
@@ -73,8 +73,8 @@ int *actualCount)	/* RETURN */
 	}

 	if ((! flist) || (! ch)) {
-	    if (flist) Xfree(flist);
-	    if (ch) Xfree(ch);
+	    Xfree(flist);
+	    Xfree(ch);
 	    _XEatDataWords(dpy, rep.length);
 	    *actualCount = 0;
 	    UnlockDisplay(dpy);
diff --git a/src/GetFPath.c b/src/GetFPath.c
index 76ff732..62ba014 100644
--- a/src/GetFPath.c
+++ b/src/GetFPath.c
@@ -57,8 +57,8 @@ char **XGetFontPath(
 	    }

 	    if ((! flist) || (! ch)) {
-		if (flist) Xfree(flist);
-		if (ch) Xfree(ch);
+		Xfree(flist);
+		Xfree(ch);
 		_XEatDataWords(dpy, rep.length);
 		UnlockDisplay(dpy);
 		SyncHandle();
diff --git a/src/GetHints.c b/src/GetHints.c
index 5cca0bc..513b4b0 100644
--- a/src/GetHints.c
+++ b/src/GetHints.c
@@ -75,7 +75,7 @@ Status XGetSizeHints (

         if ((actual_type != XA_WM_SIZE_HINTS) ||
 	    (nitems < OldNumPropSizeElements) || (actual_format != 32)) {
-		if (prop != NULL) Xfree (prop);
+		Xfree (prop);
                 return(0);
 		}
 	hints->flags	  = (prop->flags & (USPosition|USSize|PAllHints));
@@ -124,7 +124,7 @@ XWMHints *XGetWMHints (

         if ((actual_type != XA_WM_HINTS) ||
 	    (nitems < (NumPropWMHintsElements - 1)) || (actual_format != 32)) {
-		if (prop != NULL) Xfree (prop);
+		Xfree (prop);
                 return(NULL);
 		}
 	/* static copies not allowed in library, due to reentrancy constraint*/
@@ -196,7 +196,7 @@ Status XGetIconSizes (
 	    (nitems < NumPropIconSizeElements) ||
 	    (nitems % NumPropIconSizeElements != 0) ||
 	    (actual_format != 32)) {
-		if (prop != NULL) Xfree (prop);
+		Xfree (prop);
                 return(0);
 		}

@@ -204,7 +204,7 @@ Status XGetIconSizes (

 	nitems /= NumPropIconSizeElements;
 	if (! (hp = hints = Xcalloc (nitems, sizeof(XIconSize)))) {
-	    if (prop) Xfree (prop);
+	    Xfree (prop);
 	    return 0;
 	}

@@ -239,7 +239,7 @@ Status XGetCommand (
     if (!XGetTextProperty (dpy, w, &tp, XA_WM_COMMAND)) return 0;

     if (tp.encoding != XA_STRING || tp.format != 8) {
-	if (tp.value) Xfree (tp.value);
+	Xfree (tp.value);
 	return 0;
     }

@@ -254,7 +254,7 @@ Status XGetCommand (
      * create a string list and return if successful
      */
     if (!XTextPropertyToStringList (&tp, &argv, &argc)) {
-	if (tp.value) Xfree (tp.value);
+	Xfree (tp.value);
 	return (0);
     }

@@ -291,7 +291,7 @@ XGetTransientForHint(
 	return (1);
 	}
     *propWindow = None;
-    if (data) Xfree( (char *) data);
+    Xfree( (char *) data);
     return(0);
 }

@@ -333,6 +333,6 @@ XGetClassHint(
 	Xfree( (char *) data);
 	return(1);
 	}
-    if (data) Xfree( (char *) data);
+    Xfree( (char *) data);
     return(0);
 }
diff --git a/src/GetNrmHint.c b/src/GetNrmHint.c
index 5e4143b..f135fc0 100644
--- a/src/GetNrmHint.c
+++ b/src/GetNrmHint.c
@@ -23,7 +23,6 @@ PERFORMANCE OF THIS SOFTWARE.
 ******************************************************************/

 /*
-
 Copyright 1987, 1988, 1998  The Open Group

 Permission to use, copy, modify, distribute, and sell this software and its
@@ -83,7 +82,7 @@ Status XGetWMSizeHints (

     if ((actual_type != XA_WM_SIZE_HINTS) ||
 	(nitems < OldNumPropSizeElements) || (actual_format != 32)) {
-	if (prop != NULL) Xfree (prop);
+	Xfree (prop);
 	return False;
     }

diff --git a/src/GetRGBCMap.c b/src/GetRGBCMap.c
index d8a1b3f..5d570ad 100644
--- a/src/GetRGBCMap.c
+++ b/src/GetRGBCMap.c
@@ -63,7 +63,7 @@ Status XGetRGBColormaps (
     /* if wrong type or format, or too small for us, then punt */
     if ((actual_type != XA_RGB_COLOR_MAP) || (actual_format != 32) ||
 	(nitems < OldNumPropStandardColormapElements)) {
-	if (data) Xfree (data);
+	Xfree (data);
 	return False;
     }

@@ -78,7 +78,7 @@ Status XGetRGBColormaps (
 	    Screen *sp = _XScreenOfWindow (dpy, w);

 	    if (!sp) {
-		if (data) Xfree (data);
+		Xfree (data);
 		return False;
 	    }
 	    def_visual = sp->root_visual->visualid;
@@ -90,7 +90,7 @@ Status XGetRGBColormaps (
 	ncmaps = (nitems / NumPropStandardColormapElements);
 	if ((((unsigned long) ncmaps) * NumPropStandardColormapElements) !=
 	    nitems) {
-	    if (data) Xfree (data);
+	    Xfree (data);
 	    return False;
 	}
     }
@@ -101,7 +101,7 @@ Status XGetRGBColormaps (
      */
     cmaps = Xmalloc (ncmaps * sizeof (XStandardColormap));
     if (!cmaps) {
-	if (data) Xfree (data);
+	Xfree (data);
 	return False;
     }

diff --git a/src/GetStCmap.c b/src/GetStCmap.c
index ac5b0fa..1cb1e0f 100644
--- a/src/GetStCmap.c
+++ b/src/GetStCmap.c
@@ -81,7 +81,7 @@ Status XGetStandardColormap (
 	    int i;

 	    if (!sp) {
-		if (stdcmaps) Xfree (stdcmaps);
+		Xfree (stdcmaps);
 		return False;
 	    }
 	    vid = sp->root_visual->visualid;
diff --git a/src/GetWMCMapW.c b/src/GetWMCMapW.c
index 27f1e23..d3ef1fe 100644
--- a/src/GetWMCMapW.c
+++ b/src/GetWMCMapW.c
@@ -77,7 +77,7 @@ Status XGetWMColormapWindows (
       return False;

     if (actual_type != XA_WINDOW || actual_format != 32) {
-	if (data) Xfree (data);
+        Xfree (data);
 	return False;
     }

diff --git a/src/ImUtil.c b/src/ImUtil.c
index 4fc060c..0d996e8 100644
--- a/src/ImUtil.c
+++ b/src/ImUtil.c
@@ -434,8 +434,8 @@ Status XInitImage (XImage *image)

 static int _XDestroyImage (XImage *ximage)
 {
-	if (ximage->data != NULL) Xfree(ximage->data);
-	if (ximage->obdata != NULL) Xfree(ximage->obdata);
+	Xfree(ximage->data);
+	Xfree(ximage->obdata);
 	Xfree(ximage);
 	return 1;
 }
diff --git a/src/InitExt.c b/src/InitExt.c
index 0ff3732..4de46f1 100644
--- a/src/InitExt.c
+++ b/src/InitExt.c
@@ -51,7 +51,7 @@ XExtCodes *XInitExtension (
 	LockDisplay (dpy);
 	if (! (ext = Xcalloc (1, sizeof (_XExtension))) ||
 	    ! (ext->name = strdup(name))) {
-	    if (ext) Xfree(ext);
+	    Xfree(ext);
 	    UnlockDisplay(dpy);
 	    return (XExtCodes *) NULL;
 	}
diff --git a/src/KeyBind.c b/src/KeyBind.c
index f64f116..d7c78b3 100644
--- a/src/KeyBind.c
+++ b/src/KeyBind.c
@@ -271,12 +271,13 @@ _XKeyInitialize(
 	if (! keysyms) return 0;

 	LockDisplay(dpy);
-	if (dpy->keysyms)
-	    Xfree (dpy->keysyms);
+
+	Xfree (dpy->keysyms);
 	dpy->keysyms = keysyms;
 	dpy->keysyms_per_keycode = per;
 	if (dpy->modifiermap)
 	    ResetModMap(dpy);
+
 	UnlockDisplay(dpy);
     }
     if (!dpy->modifiermap)
@@ -929,8 +930,8 @@ XRebindKeysym (
 	((! (p->string = Xmalloc(nbytes))) && (nbytes > 0)) ||
 	((! (p->modifiers = Xmalloc(nb))) && (nb > 0))) {
 	if (p) {
-	    if (p->string) Xfree(p->string);
-	    if (p->modifiers) Xfree(p->modifiers);
+	    Xfree(p->string);
+	    Xfree(p->modifiers);
 	    Xfree(p);
 	}
 	UnlockDisplay(dpy);
diff --git a/src/ListExt.c b/src/ListExt.c
index f40924d..431ae67 100644
--- a/src/ListExt.c
+++ b/src/ListExt.c
@@ -62,8 +62,8 @@ char **XListExtensions(
 	    }

 	    if ((!list) || (!ch)) {
-		if (list) Xfree(list);
-		if (ch)   Xfree(ch);
+		Xfree(list);
+		Xfree(ch);
 		_XEatDataWords(dpy, rep.length);
 		UnlockDisplay(dpy);
 		SyncHandle();
diff --git a/src/ModMap.c b/src/ModMap.c
index 78d635b..a809aa2 100644
--- a/src/ModMap.c
+++ b/src/ModMap.c
@@ -50,7 +50,7 @@ XGetModifierMapping(register Display *dpy)
     } else
 	res = NULL;
     if ((! res) || (! res->modifiermap)) {
-	if (res) Xfree(res);
+	Xfree(res);
 	res = (XModifierKeymap *) NULL;
 	_XEatDataWords(dpy, rep.length);
     } else {
@@ -114,8 +114,7 @@ int
 XFreeModifiermap(XModifierKeymap *map)
 {
     if (map) {
-	if (map->modifiermap)
-	    Xfree(map->modifiermap);
+        Xfree(map->modifiermap);
 	Xfree(map);
     }
     return 1;
diff --git a/src/OpenDis.c b/src/OpenDis.c
index 3793814..fc2cc16 100644
--- a/src/OpenDis.c
+++ b/src/OpenDis.c
@@ -590,8 +590,7 @@ void _XFreeDisplayStructure(Display *dpy)
 	while (dpy->ext_procs) {
 	    _XExtension *ext = dpy->ext_procs;
 	    dpy->ext_procs = ext->next;
-	    if (ext->name)
-		Xfree (ext->name);
+	    Xfree (ext->name);
 	    Xfree (ext);
 	}
 	if (dpy->im_filters)
@@ -656,23 +655,17 @@ void _XFreeDisplayStructure(Display *dpy)
 	    }

 	free(dpy->display_name);
-	if (dpy->vendor)
-	   Xfree (dpy->vendor);
-
-        if (dpy->buffer)
-	   Xfree (dpy->buffer);
-	if (dpy->keysyms)
-	   Xfree (dpy->keysyms);
-	if (dpy->xdefaults)
-	   Xfree (dpy->xdefaults);
-	if (dpy->error_vec)
-	    Xfree (dpy->error_vec);
+	
+	Xfree (dpy->vendor);
+	Xfree (dpy->buffer);	
+	Xfree (dpy->keysyms);
+	Xfree (dpy->xdefaults);
+	Xfree (dpy->error_vec);

 	_XFreeExtData (dpy->ext_data);
-	if (dpy->free_funcs)
-	    Xfree (dpy->free_funcs);
- 	if (dpy->scratch_buffer)
- 	    Xfree (dpy->scratch_buffer);
+
+	Xfree (dpy->free_funcs);
+ 	Xfree (dpy->scratch_buffer);
 	FreeDisplayLock(dpy);

 	if (dpy->qfree) {
@@ -687,8 +680,7 @@ void _XFreeDisplayStructure(Display *dpy)
 	while (dpy->im_fd_info) {
 	    struct _XConnectionInfo *conni = dpy->im_fd_info;
 	    dpy->im_fd_info = conni->next;
-	    if (conni->watch_data)
-		Xfree (conni->watch_data);
+	    Xfree (conni->watch_data);
 	    Xfree (conni);
 	}
 	if (dpy->conn_watchers) {
@@ -696,8 +688,8 @@ void _XFreeDisplayStructure(Display *dpy)
 	    dpy->conn_watchers = watcher->next;
 	    Xfree (watcher);
 	}
-	if (dpy->filedes)
-	    Xfree (dpy->filedes);
+
+	Xfree (dpy->filedes);

 	_XFreeX11XCBStructure(dpy);

diff --git a/src/PutImage.c b/src/PutImage.c
index e6ac9a2..87ca3da 100644
--- a/src/PutImage.c
+++ b/src/PutImage.c
@@ -740,8 +740,7 @@ SendXYImage(
 		    bytes_per_src, bytes_per_line,
 		    bytes_per_dest, req->height, half_order);

-    if (extra)
-	Xfree(extra);
+    Xfree(extra);

     if (buf == dpy->bufptr)
 	dpy->bufptr += length;
@@ -792,10 +791,9 @@ SendZImage(
 	((long)image->bytes_per_line == bytes_per_dest) &&
 	((req_xoffset == 0) ||
 	 ((req_yoffset + req->height) < (unsigned)image->height))) {
-	Data(dpy, (char *)src, length);
-	if (shifted_src)
-	    Xfree(shifted_src);
-	return;
+            Data(dpy, (char *)src, length);
+            Xfree(shifted_src);
+	    return;
     }

     length = ROUNDUP(length, 4);
@@ -804,7 +802,7 @@ SendZImage(
     else
 	if ((dest = (unsigned char *)
 	     _XAllocScratch(dpy, length)) == NULL) {
-	    if (shifted_src) Xfree(shifted_src);
+	    Xfree(shifted_src);
 	    UnGetReq(PutImage);
 	    return;
 	}
@@ -831,8 +829,7 @@ SendZImage(
     else
 	_XSend(dpy, (char *)dest, length);

-    if (shifted_src)
-        Xfree(shifted_src);
+    Xfree(shifted_src);
 }

 static void
diff --git a/src/RdBitF.c b/src/RdBitF.c
index 31bf583..8a1ad85 100644
--- a/src/RdBitF.c
+++ b/src/RdBitF.c
@@ -137,7 +137,7 @@ XReadBitmapFileData (

     /* error cleanup and return macro	*/
 #define	RETURN(code) \
-{ if (bits) Xfree (bits); fclose (fstream); return code; }
+{ Xfree (bits); fclose (fstream); return code; }

     while (fgets(line, MAX_SIZE, fstream)) {
 	if (strlen(line) == MAX_SIZE-1)
diff --git a/src/ScrResStr.c b/src/ScrResStr.c
index 0601c86..4a5491a 100644
--- a/src/ScrResStr.c
+++ b/src/ScrResStr.c
@@ -48,8 +48,7 @@ char *XScreenResourceString(Screen *screen)
 			   (unsigned char **) &val) == Success) {
 	if ((actual_type == XA_STRING) && (actual_format == 8))
 	    return val;
-	if (val)
-	    Xfree(val);
+	Xfree(val);
     }
     return (char *)NULL;
 }
diff --git a/src/StBytes.c b/src/StBytes.c
index ec6c2e2..d8fca17 100644
--- a/src/StBytes.c
+++ b/src/StBytes.c
@@ -74,7 +74,7 @@ char *XFetchBuffer (
 	*nbytes = nitems;
 	return((char *)data);
 	}
-    if ((char *) data != NULL) Xfree (data);
+    Xfree (data);
     return(NULL);
 }

diff --git a/src/XlibInt.c b/src/XlibInt.c
index a5350e9..80c1298 100644
--- a/src/XlibInt.c
+++ b/src/XlibInt.c
@@ -398,8 +398,7 @@ _XUnregisterInternalConnection(
 		 watch=watch->next, wd++) {
 		(*watch->fn) (dpy, watch->client_data, fd, False, wd);
 	    }
-	    if (info_list->watch_data)
-		Xfree (info_list->watch_data);
+	    Xfree (info_list->watch_data);
 	    Xfree (info_list);
 	    break;
 	}
@@ -1482,8 +1481,9 @@ char *_XAllocScratch(
 	unsigned long nbytes)
 {
 	if (nbytes > dpy->scratch_length) {
-	    if (dpy->scratch_buffer) Xfree (dpy->scratch_buffer);
-	    if ((dpy->scratch_buffer = Xmalloc(nbytes)))
+	    Xfree (dpy->scratch_buffer);
+	    dpy->scratch_buffer = Xmalloc(nbytes);
+	    if (dpy->scratch_buffer)
 		dpy->scratch_length = nbytes;
 	    else dpy->scratch_length = 0;
 	}
@@ -1511,8 +1511,8 @@ void _XFreeTemp(
     char *buf,
     unsigned long nbytes)
 {
-    if (dpy->scratch_buffer)
-	Xfree(dpy->scratch_buffer);
+
+    Xfree(dpy->scratch_buffer);
     dpy->scratch_buffer = buf;
     dpy->scratch_length = nbytes;
 }
-- 
1.8.4.5



More information about the xorg-devel mailing list