[PATCH:xdm 2/5] Stop checking for NULL before calling free()

Alan Coopersmith alan.coopersmith at oracle.com
Sat May 14 11:01:30 PDT 2011


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 chooser/chooser.c |    3 +--
 xdm/access.c      |   15 +++++----------
 xdm/auth.c        |    9 +++------
 xdm/dm.c          |    3 +--
 xdm/dpylist.c     |   50 ++++++++++++++++++++++++--------------------------
 xdm/krb5auth.c    |    3 +--
 xdm/server.c      |    3 +--
 xdm/socket.c      |    3 +--
 xdm/util.c        |    3 +--
 xdm/xdmauth.c     |    6 ++----
 xdm/xdmcp.c       |    4 ++--
 11 files changed, 42 insertions(+), 60 deletions(-)

diff --git a/chooser/chooser.c b/chooser/chooser.c
index d3d08ea..01201b7 100644
--- a/chooser/chooser.c
+++ b/chooser/chooser.c
@@ -312,8 +312,7 @@ RebuildTable (int size)
 	qsort (newTable, size, sizeof (char *), HostnameCompare);
     }
     XawListChange (list, newTable, size, 0, TRUE);
-    if (NameTable)
-	free ((char *) NameTable);
+    free ((char *) NameTable);
     NameTable = newTable;
     NameTableSize = size;
 }
diff --git a/xdm/access.c b/xdm/access.c
index eae5286..ceace37 100644
--- a/xdm/access.c
+++ b/xdm/access.c
@@ -784,8 +784,7 @@ int ForEachMatchingIndirectHost (
 	}
 	break;
     }
-    if (clientName)
-	free (clientName);
+    free (clientName);
     return haveLocalhost;
 }
 
@@ -823,14 +822,12 @@ int UseChooser (
 	if (d->notAllowed)
 	    break;
 	if (d->chooser && !IndirectChoice (clientAddress, connectionType)) {
-	    if (clientName)
-		free (clientName);
+	    free (clientName);
 	    return 1;
 	}
 	break;
     }
-    if (clientName)
-	free (clientName);
+    free (clientName);
     return 0;
 }
 
@@ -879,8 +876,7 @@ void ForEachChooserHost (
 	}
 	break;
     }
-    if (clientName)
-	free (clientName);
+    free (clientName);
     if (haveLocalhost)
 	(*function) (connectionType, getLocalAddress(), closure);
 }
@@ -928,8 +924,7 @@ int AcceptableDisplayAddress (
 	}
 	break;
     }
-    if (clientName)
-	free (clientName);
+    free (clientName);
     return (d != 0) && (d->notAllowed == 0)
 	&& (type == BROADCAST_QUERY ? d->notBroadcast == 0 : 1);
 }
diff --git a/xdm/auth.c b/xdm/auth.c
index 63cd15e..ec3a1cc 100644
--- a/xdm/auth.c
+++ b/xdm/auth.c
@@ -505,8 +505,7 @@ SetLocalAuthorization (struct display *d)
     for (i = 0; d->authNames[i]; i++)
 	;
     d->authNameNum = i;
-    if (d->authNameLens)
-	free ((char *) d->authNameLens);
+    free ((char *) d->authNameLens);
     d->authNameLens = (unsigned short *) malloc
 				(d->authNameNum * sizeof (unsigned short));
     if (!d->authNameLens)
@@ -663,10 +662,8 @@ doneAddrs (void)
 	struct addrList	*a, *n;
 	for (a = addrs; a; a = n) {
 		n = a->next;
-		if (a->address)
-			free (a->address);
-		if (a->number)
-			free (a->number);
+		free (a->address);
+		free (a->number);
 		free ((char *) a);
 	}
 }
diff --git a/xdm/dm.c b/xdm/dm.c
index 9d0f0e8..cd0ee25 100644
--- a/xdm/dm.c
+++ b/xdm/dm.c
@@ -733,8 +733,7 @@ SetWindowPath(struct display *d)
 	} else {
 		asprintf(&newwindowpath, "%s:%lu", windowpath, num);
 	}
-	if (d->windowPath)
-		free(d->windowPath);
+	free(d->windowPath);
 	d->windowPath = newwindowpath;
 }
 
diff --git a/xdm/dpylist.c b/xdm/dpylist.c
index dccd679..148f524 100644
--- a/xdm/dpylist.c
+++ b/xdm/dpylist.c
@@ -118,8 +118,6 @@ FindDisplayByAddress (XdmcpNetaddr addr, int addrlen, CARD16 displayNumber)
 
 #endif /* XDMCP */
 
-#define IfFree(x)  if (x) free ((char *) x)
-
 void
 RemoveDisplay (struct display *old)
 {
@@ -134,43 +132,43 @@ RemoveDisplay (struct display *old)
 		p->next = d->next;
 	    else
 		displays = d->next;
-	    IfFree (d->name);
-	    IfFree (d->class);
+	    free (d->name);
+	    free (d->class);
 	    for (x = d->argv; x && *x; x++)
-		IfFree (*x);
-	    IfFree (d->argv);
-	    IfFree (d->resources);
-	    IfFree (d->xrdb);
-	    IfFree (d->setup);
-	    IfFree (d->startup);
-	    IfFree (d->reset);
-	    IfFree (d->session);
-	    IfFree (d->userPath);
-	    IfFree (d->systemPath);
-	    IfFree (d->systemShell);
-	    IfFree (d->failsafeClient);
-	    IfFree (d->chooser);
+		free (*x);
+	    free (d->argv);
+	    free (d->resources);
+	    free (d->xrdb);
+	    free (d->setup);
+	    free (d->startup);
+	    free (d->reset);
+	    free (d->session);
+	    free (d->userPath);
+	    free (d->systemPath);
+	    free (d->systemShell);
+	    free (d->failsafeClient);
+	    free (d->chooser);
 	    if (d->authorizations)
 	    {
 		for (i = 0; i < d->authNum; i++)
 		    XauDisposeAuth (d->authorizations[i]);
 		free ((char *) d->authorizations);
 	    }
-	    IfFree (d->clientAuthFile);
+	    free (d->clientAuthFile);
 	    if (d->authFile)
 		(void) unlink (d->authFile);
-	    IfFree (d->authFile);
-	    IfFree (d->userAuthDir);
+	    free (d->authFile);
+	    free (d->userAuthDir);
 	    for (x = d->authNames; x && *x; x++)
-		IfFree (*x);
-	    IfFree (d->authNames);
-	    IfFree (d->authNameLens);
+		free (*x);
+	    free (d->authNames);
+	    free (d->authNameLens);
 #ifdef XDMCP
-	    IfFree (d->peer);
-	    IfFree (d->from);
+	    free (d->peer);
+	    free (d->from);
 	    XdmcpDisposeARRAY8 (&d->clientAddr);
 #endif
-	    IfFree (d->windowPath);
+	    free (d->windowPath);
 	    free ((char *) d);
 	    break;
 	}
diff --git a/xdm/krb5auth.c b/xdm/krb5auth.c
index 1777493..2316945 100644
--- a/xdm/krb5auth.c
+++ b/xdm/krb5auth.c
@@ -249,8 +249,7 @@ Krb5Init(
 	else
 	    LogError("%s while getting initial Krb5 credentials for \"%s\"\n",
 		     error_message(code), code2 ? name : my_name);
-	if (my_name)
-	    free (my_name);
+	free (my_name);
 	return 1;
     }
     krb5_cc_close(ccache);
diff --git a/xdm/server.c b/xdm/server.c
index 8ffa9df..9d4c4e2 100644
--- a/xdm/server.c
+++ b/xdm/server.c
@@ -252,8 +252,7 @@ GetRemoteAddress (struct display *d, int fd)
     struct netbuf	netb;
 # endif
 
-    if (d->peer)
-	free ((char *) d->peer);
+    free ((char *) d->peer);
 # ifdef STREAMSCONN
     netb.maxlen = sizeof(buf);
     netb.buf = buf;
diff --git a/xdm/socket.c b/xdm/socket.c
index c7cc9ba..29e344f 100644
--- a/xdm/socket.c
+++ b/xdm/socket.c
@@ -228,8 +228,7 @@ DestroyListeningSocket (struct socklist *s)
 
 	for (g = s->mcastgroups; g != NULL; g = n) {
 	    n = g->next;
-	    if (g->addr)
-		free(g->addr);
+	    free(g->addr);
 	    free(g);
 	}
 	s->mcastgroups = NULL;
diff --git a/xdm/util.c b/xdm/util.c
index 572b9c5..3058450 100644
--- a/xdm/util.c
+++ b/xdm/util.c
@@ -235,8 +235,7 @@ parseArgs (char **argv, char *string)
 					LogOutOfMem ("parseArgs");
 					free ((char *) argv);
 					free (newargv);
-					if (save)
-						free (save);
+					free (save);
 					return NULL;
 				} else {
 				    argv = newargv;
diff --git a/xdm/xdmauth.c b/xdm/xdmauth.c
index 189062b..e01b306 100644
--- a/xdm/xdmauth.c
+++ b/xdm/xdmauth.c
@@ -162,10 +162,8 @@ XdmGetXdmcpAuth (struct protoDisplay *pdpy,
     if (!fileauth->name || !fileauth->data)
     {
 	XauDisposeAuth (xdmcpauth);
-	if (fileauth->name)
-	    free ((char *) fileauth->name);
-	if (fileauth->data)
-	    free ((char *) fileauth->data);
+	free ((char *) fileauth->name);
+	free ((char *) fileauth->data);
 	free ((char *) fileauth);
 	return;
     }
diff --git a/xdm/xdmcp.c b/xdm/xdmcp.c
index 24d4396..96910c1 100644
--- a/xdm/xdmcp.c
+++ b/xdm/xdmcp.c
@@ -1293,8 +1293,8 @@ manage (
     }
 abort:
     XdmcpDisposeARRAY8 (&displayClass);
-    if (name) free ((char*) name);
-    if (class) free ((char*) class);
+    free ((char*) name);
+    free ((char*) class);
 }
 
 void
-- 
1.7.3.2



More information about the xorg-devel mailing list