[PATCH] Replace xalloc with malloc
Tomas Carnecky
tom at dbservice.com
Wed Jun 16 11:28:29 PDT 2010
Same for xfree/xrealloc/xcalloc. Also, the return value from
malloc/realloc/calloc doesn't require a cast, same for the
argument of free(). Also remove if()'s that check if the
pointer that is about to be passed to free() is NULL, since
free(NULL) is allowed.
Signed-off-by: Tomas Carnecky <tom at dbservice.com>
---
libxtrans is also the source of another heap of warnings:
format not a string literal, argument types not checked
This comes from the PRMSG() macro. I have a patch ready
which converts the macro to use C99 varargs. I sent it to
the mailing list on Feb 9, 2009. But contrary to the comment
I made then, it does seem to fix the warnings. I'd need to
update it though, as it won't apply cleany on top of this
patch.
Xtrans.c | 78 ++++++++++++++++++++++++++-------------------------------
Xtranslcl.c | 51 ++++++++++++++++++-------------------
Xtranssock.c | 54 ++++++++++++++++++----------------------
Xtranstli.c | 40 ++++++++++++++---------------
Xtransutil.c | 14 ++++------
transport.c | 4 ---
6 files changed, 110 insertions(+), 131 deletions(-)
diff --git a/Xtrans.c b/Xtrans.c
index 7b18f10..24bdf42 100644
--- a/Xtrans.c
+++ b/Xtrans.c
@@ -136,16 +136,10 @@ TRANS(FreeConnInfo) (XtransConnInfo ciptr)
{
PRMSG (3,"FreeConnInfo(%p)\n", ciptr, 0, 0);
- if (ciptr->addr)
- xfree (ciptr->addr);
-
- if (ciptr->peeraddr)
- xfree (ciptr->peeraddr);
-
- if (ciptr->port)
- xfree (ciptr->port);
-
- xfree ((char *) ciptr);
+ free (ciptr->addr);
+ free (ciptr->peeraddr);
+ free (ciptr->port);
+ free (ciptr);
}
@@ -213,7 +207,7 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
/* Copy the string so it can be changed */
- tmpptr = mybuf = (char *) xalloc (strlen (address) + 1);
+ tmpptr = mybuf = malloc (strlen (address) + 1);
strcpy (mybuf, address);
/* Parse the string to get each component */
@@ -230,7 +224,7 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
*protocol = NULL;
*host = NULL;
*port = NULL;
- xfree (tmpptr);
+ free (tmpptr);
return 0;
}
@@ -280,7 +274,7 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
*protocol = NULL;
*host = NULL;
*port = NULL;
- xfree (tmpptr);
+ free (tmpptr);
return 0;
}
@@ -363,46 +357,46 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
* string space for them.
*/
- if ((*protocol = (char *) xalloc(strlen (_protocol) + 1)) == NULL)
+ if ((*protocol = malloc(strlen (_protocol) + 1)) == NULL)
{
/* Malloc failed */
*port = NULL;
*host = NULL;
*protocol = NULL;
- xfree (tmpptr);
+ free (tmpptr);
return 0;
}
else
strcpy (*protocol, _protocol);
- if ((*host = (char *) xalloc (strlen (_host) + 1)) == NULL)
+ if ((*host = malloc (strlen (_host) + 1)) == NULL)
{
/* Malloc failed */
*port = NULL;
*host = NULL;
- xfree (*protocol);
+ free (*protocol);
*protocol = NULL;
- xfree (tmpptr);
+ free (tmpptr);
return 0;
}
else
strcpy (*host, _host);
- if ((*port = (char *) xalloc (strlen (_port) + 1)) == NULL)
+ if ((*port = malloc (strlen (_port) + 1)) == NULL)
{
/* Malloc failed */
*port = NULL;
- xfree (*host);
+ free (*host);
*host = NULL;
- xfree (*protocol);
+ free (*protocol);
*protocol = NULL;
- xfree (tmpptr);
+ free (tmpptr);
return 0;
}
else
strcpy (*port, _port);
- xfree (tmpptr);
+ free (tmpptr);
return 1;
}
@@ -447,9 +441,9 @@ TRANS(Open) (int type, char *address)
PRMSG (1,"Open: Unable to find transport for %s\n",
protocol, 0, 0);
- xfree (protocol);
- xfree (host);
- xfree (port);
+ free (protocol);
+ free (host);
+ free (port);
return NULL;
}
@@ -488,17 +482,17 @@ TRANS(Open) (int type, char *address)
PRMSG (1,"Open: transport open failed for %s/%s:%s\n",
protocol, host, port);
}
- xfree (protocol);
- xfree (host);
- xfree (port);
+ free (protocol);
+ free (host);
+ free (port);
return NULL;
}
ciptr->transptr = thistrans;
ciptr->port = port; /* We need this for TRANS(Reopen) */
- xfree (protocol);
- xfree (host);
+ free (protocol);
+ free (host);
return ciptr;
}
@@ -540,7 +534,7 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
return NULL;
}
- if ((save_port = (char *) xalloc (strlen (port) + 1)) == NULL)
+ if ((save_port = malloc (strlen (port) + 1)) == NULL)
{
PRMSG (1,"Reopen: Unable to malloc port string\n", 0, 0, 0);
@@ -669,7 +663,7 @@ TRANS(GetReopenInfo) (XtransConnInfo ciptr,
*trans_id = Xtransports[i].transport_id;
*fd = ciptr->fd;
- if ((*port = (char *) xalloc (strlen (ciptr->port) + 1)) == NULL)
+ if ((*port = malloc (strlen (ciptr->port) + 1)) == NULL)
return 0;
else
{
@@ -860,16 +854,16 @@ TRANS(Connect) (XtransConnInfo ciptr, char *address)
{
PRMSG (1,"Connect: Missing port specification in %s\n",
address, 0, 0);
- if (protocol) xfree (protocol);
- if (host) xfree (host);
+ free (protocol);
+ free (host);
return -1;
}
ret = ciptr->transptr->Connect (ciptr, host, port);
- if (protocol) xfree (protocol);
- if (host) xfree (host);
- if (port) xfree (port);
+ free (protocol);
+ free (host);
+ free (port);
return ret;
}
@@ -967,7 +961,7 @@ TRANS(GetMyAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
*familyp = ciptr->family;
*addrlenp = ciptr->addrlen;
- if ((*addrp = (Xtransaddr *) xalloc (ciptr->addrlen)) == NULL)
+ if ((*addrp = malloc (ciptr->addrlen)) == NULL)
{
PRMSG (1,"GetMyAddr: malloc failed\n", 0, 0, 0);
return -1;
@@ -987,7 +981,7 @@ TRANS(GetPeerAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
*familyp = ciptr->family;
*addrlenp = ciptr->peeraddrlen;
- if ((*addrp = (Xtransaddr *) xalloc (ciptr->peeraddrlen)) == NULL)
+ if ((*addrp = malloc (ciptr->peeraddrlen)) == NULL)
{
PRMSG (1,"GetPeerAddr: malloc failed\n", 0, 0, 0);
return -1;
@@ -1157,7 +1151,7 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
if (*count_ret > 0)
{
- if ((*ciptrs_ret = (XtransConnInfo *) xalloc (
+ if ((*ciptrs_ret = malloc (
*count_ret * sizeof (XtransConnInfo))) == NULL)
{
return -1;
@@ -1256,7 +1250,7 @@ TRANS(MakeAllCLTSServerListeners) (char *port, int *partial, int *count_ret,
if (*count_ret > 0)
{
- if ((*ciptrs_ret = (XtransConnInfo *) xalloc (
+ if ((*ciptrs_ret = malloc (
*count_ret * sizeof (XtransConnInfo))) == NULL)
{
return -1;
diff --git a/Xtranslcl.c b/Xtranslcl.c
index cb5836c..210ef0b 100644
--- a/Xtranslcl.c
+++ b/Xtranslcl.c
@@ -153,7 +153,7 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path)
ciptr->family = AF_UNIX;
ciptr->addrlen = sizeof (struct sockaddr_un);
- if ((sunaddr = (struct sockaddr_un *) xalloc (ciptr->addrlen)) == NULL)
+ if ((sunaddr = malloc (ciptr->addrlen)) == NULL)
{
PRMSG(1,"FillAddrInfo: failed to allocate memory for addr\n", 0, 0, 0);
return 0;
@@ -163,7 +163,7 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path)
if (strlen(sun_path) > sizeof(sunaddr->sun_path) - 1) {
PRMSG(1, "FillAddrInfo: path too long\n", 0, 0, 0);
- xfree((char *) sunaddr);
+ free(sunaddr);
return 0;
}
strcpy (sunaddr->sun_path, sun_path);
@@ -175,13 +175,12 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path)
ciptr->peeraddrlen = sizeof (struct sockaddr_un);
- if ((p_sunaddr = (struct sockaddr_un *) xalloc (
- ciptr->peeraddrlen)) == NULL)
+ if ((p_sunaddr = malloc (ciptr->peeraddrlen)) == NULL)
{
PRMSG(1,
"FillAddrInfo: failed to allocate memory for peer addr\n",
0,0,0);
- xfree ((char *) sunaddr);
+ free (sunaddr);
ciptr->addr = NULL;
return 0;
@@ -191,7 +190,7 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path)
if (strlen(peer_sun_path) > sizeof(p_sunaddr->sun_path) - 1) {
PRMSG(1, "FillAddrInfo: peer path too long\n", 0, 0, 0);
- xfree((char *) p_sunaddr);
+ free(p_sunaddr);
return 0;
}
strcpy (p_sunaddr->sun_path, peer_sun_path);
@@ -618,7 +617,7 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
*/
newciptr->addrlen=ciptr->addrlen;
- if( (newciptr->addr=(char *)xalloc(newciptr->addrlen)) == NULL ) {
+ if( (newciptr->addr=malloc(newciptr->addrlen)) == NULL ) {
PRMSG(1,"PTSAccept: failed to allocate memory for peer addr\n",
0,0,0);
close(newfd);
@@ -629,10 +628,10 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);
newciptr->peeraddrlen=sizeof(struct sockaddr_un);
- if( (sunaddr=(struct sockaddr_un *)xalloc(newciptr->peeraddrlen)) == NULL ) {
+ if( (sunaddr=malloc(newciptr->peeraddrlen)) == NULL ) {
PRMSG(1,"PTSAccept: failed to allocate memory for peer addr\n",
0,0,0);
- xfree(newciptr->addr);
+ free(newciptr->addr);
close(newfd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
@@ -898,7 +897,7 @@ TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
*/
newciptr->family=ciptr->family;
newciptr->addrlen=ciptr->addrlen;
- if( (newciptr->addr=(char *)xalloc(newciptr->addrlen)) == NULL ) {
+ if( (newciptr->addr=malloc(newciptr->addrlen)) == NULL ) {
PRMSG(1,
"NAMEDAccept: failed to allocate memory for pipe addr\n",
0,0,0);
@@ -910,11 +909,11 @@ TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);
newciptr->peeraddrlen=newciptr->addrlen;
- if( (newciptr->peeraddr=(char *)xalloc(newciptr->peeraddrlen)) == NULL ) {
+ if( (newciptr->peeraddr=malloc(newciptr->peeraddrlen)) == NULL ) {
PRMSG(1,
"NAMEDAccept: failed to allocate memory for peer addr\n",
0,0,0);
- xfree(newciptr->addr);
+ free(newciptr->addr);
close(str.fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
@@ -1238,7 +1237,7 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
*/
newciptr->addrlen=ciptr->addrlen;
- if( (newciptr->addr=(char *)xalloc(newciptr->addrlen)) == NULL ) {
+ if( (newciptr->addr=malloc(newciptr->addrlen)) == NULL ) {
PRMSG(1,
"SCOAccept: failed to allocate memory for peer addr\n",
0,0,0);
@@ -1253,11 +1252,11 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
#endif
newciptr->peeraddrlen=newciptr->addrlen;
- if( (newciptr->peeraddr=(char *)xalloc(newciptr->peeraddrlen)) == NULL ) {
+ if( (newciptr->peeraddr=malloc(newciptr->peeraddrlen)) == NULL ) {
PRMSG(1,
"SCOAccept: failed to allocate memory for peer addr\n",
0,0,0);
- xfree(newciptr->addr);
+ free(newciptr->addr);
close(fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
@@ -1686,7 +1685,7 @@ TRANS(LocalInitTransports)(char *protocol)
if( strcmp(protocol,"local") && strcmp(protocol,"LOCAL") )
{
- workingXLOCAL=freeXLOCAL=(char *)xalloc (strlen (protocol) + 1);
+ workingXLOCAL=freeXLOCAL=malloc (strlen (protocol) + 1);
if (workingXLOCAL)
strcpy (workingXLOCAL, protocol);
}
@@ -1694,7 +1693,7 @@ TRANS(LocalInitTransports)(char *protocol)
XLOCAL=(char *)getenv("XLOCAL");
if(XLOCAL==NULL)
XLOCAL=DEF_XLOCAL;
- workingXLOCAL=freeXLOCAL=(char *)xalloc (strlen (XLOCAL) + 1);
+ workingXLOCAL=freeXLOCAL=malloc (strlen (XLOCAL) + 1);
if (workingXLOCAL)
strcpy (workingXLOCAL, XLOCAL);
}
@@ -1705,7 +1704,7 @@ TRANS(LocalEndTransports)(void)
{
PRMSG(3,"LocalEndTransports()\n", 0,0,0 );
- xfree(freeXLOCAL);
+ free(freeXLOCAL);
}
#define TYPEBUFSIZE 32
@@ -1830,7 +1829,7 @@ TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port)
*/
#endif /* X11_t */
- if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+ if( (ciptr=calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
{
PRMSG(1,"LocalOpenClient: calloc(1,%d) failed\n",
sizeof(struct _XtransConnInfo),0,0 );
@@ -1872,7 +1871,7 @@ TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port)
if( ciptr->fd < 0 )
{
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -1905,7 +1904,7 @@ TRANS(LocalOpenServer)(int type, char *protocol, char *host, char *port)
*/
#endif /* X11_t */
- if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+ if( (ciptr=calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
{
PRMSG(1,"LocalOpenServer: calloc(1,%d) failed\n",
sizeof(struct _XtransConnInfo),0,0 );
@@ -1942,7 +1941,7 @@ TRANS(LocalOpenServer)(int type, char *protocol, char *host, char *port)
}
}
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -1960,7 +1959,7 @@ TRANS(LocalReopenServer)(int type, int index, int fd, char *port)
PRMSG(2,"LocalReopenServer(%d,%d,%d)\n", type, index, fd);
- if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+ if( (ciptr=calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
{
PRMSG(1,"LocalReopenServer: calloc(1,%d) failed\n",
sizeof(struct _XtransConnInfo),0,0 );
@@ -1989,7 +1988,7 @@ TRANS(LocalReopenServer)(int type, int index, int fd, char *port)
return ciptr;
}
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -2192,7 +2191,7 @@ TRANS(LocalAccept)(XtransConnInfo ciptr, int *status)
transptr=(LOCALtrans2dev *)ciptr->priv;
- if( (newciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo)))==NULL )
+ if( (newciptr=calloc(1,sizeof(struct _XtransConnInfo)))==NULL )
{
PRMSG(1,"LocalAccept: calloc(1,%d) failed\n",
sizeof(struct _XtransConnInfo),0,0 );
@@ -2204,7 +2203,7 @@ TRANS(LocalAccept)(XtransConnInfo ciptr, int *status)
if( newciptr->fd < 0 )
{
- xfree(newciptr);
+ free(newciptr);
return NULL;
}
diff --git a/Xtranssock.c b/Xtranssock.c
index 7106f5d..e7b7659 100644
--- a/Xtranssock.c
+++ b/Xtranssock.c
@@ -315,7 +315,7 @@ TRANS(SocketINETGetAddr) (XtransConnInfo ciptr)
* Everything looks good: fill in the XtransConnInfo structure.
*/
- if ((ciptr->addr = (char *) xalloc (namelen)) == NULL)
+ if ((ciptr->addr = malloc (namelen)) == NULL)
{
PRMSG (1,
"SocketINETGetAddr: Can't allocate space for the addr\n",
@@ -383,7 +383,7 @@ TRANS(SocketINETGetPeerAddr) (XtransConnInfo ciptr)
* Everything looks good: fill in the XtransConnInfo structure.
*/
- if ((ciptr->peeraddr = (char *) xalloc (namelen)) == NULL)
+ if ((ciptr->peeraddr = malloc (namelen)) == NULL)
{
PRMSG (1,
"SocketINETGetPeerAddr: Can't allocate space for the addr\n",
@@ -406,8 +406,7 @@ TRANS(SocketOpen) (int i, int type)
PRMSG (3,"SocketOpen(%d,%d)\n", i, type, 0);
- if ((ciptr = (XtransConnInfo) xcalloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((ciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
PRMSG (1, "SocketOpen: malloc failed\n", 0, 0, 0);
return NULL;
@@ -427,7 +426,7 @@ TRANS(SocketOpen) (int i, int type)
PRMSG (2, "SocketOpen: socket() failed for %s\n",
Sockettrans2devtab[i].transname, 0, 0);
- xfree ((char *) ciptr);
+ free (ciptr);
return NULL;
}
@@ -483,8 +482,7 @@ TRANS(SocketReopen) (int i, int type, int fd, char *port)
}
#endif /*SOCK_MAXADDRLEN*/
- if ((ciptr = (XtransConnInfo) xcalloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((ciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
PRMSG (1, "SocketReopen: malloc(ciptr) failed\n", 0, 0, 0);
return NULL;
@@ -492,14 +490,14 @@ TRANS(SocketReopen) (int i, int type, int fd, char *port)
ciptr->fd = fd;
- if ((addr = (struct sockaddr *) xcalloc (1, portlen + 2)) == NULL) {
+ if ((addr = calloc (1, portlen + 2)) == NULL) {
PRMSG (1, "SocketReopen: malloc(addr) failed\n", 0, 0, 0);
return NULL;
}
ciptr->addr = (char *) addr;
ciptr->addrlen = portlen + 2;
- if ((ciptr->peeraddr = (char *) xcalloc (1, portlen + 2)) == NULL) {
+ if ((ciptr->peeraddr = calloc (1, portlen + 2)) == NULL) {
PRMSG (1, "SocketReopen: malloc(portaddr) failed\n", 0, 0, 0);
return NULL;
}
@@ -1141,7 +1139,7 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
namelen = sizeof (sockname); /* this will always make it the same size */
- if ((ciptr->addr = (char *) xalloc (namelen)) == NULL)
+ if ((ciptr->addr = malloc (namelen)) == NULL)
{
PRMSG (1,
"SocketUNIXCreateListener: Can't allocate space for the addr\n",
@@ -1256,8 +1254,7 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
PRMSG (2, "SocketINETAccept(%p,%d)\n", ciptr, ciptr->fd, 0);
- if ((newciptr = (XtransConnInfo) xcalloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((newciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
PRMSG (1, "SocketINETAccept: malloc failed\n", 0, 0, 0);
*status = TRANS_ACCEPT_BAD_MALLOC;
@@ -1271,7 +1268,7 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
errno = WSAGetLastError();
#endif
PRMSG (1, "SocketINETAccept: accept() failed\n", 0, 0, 0);
- xfree (newciptr);
+ free (newciptr);
*status = TRANS_ACCEPT_FAILED;
return NULL;
}
@@ -1299,7 +1296,7 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
"SocketINETAccept: ...SocketINETGetAddr() failed:\n",
0, 0, 0);
close (newciptr->fd);
- xfree (newciptr);
+ free (newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
@@ -1310,8 +1307,8 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
"SocketINETAccept: ...SocketINETGetPeerAddr() failed:\n",
0, 0, 0);
close (newciptr->fd);
- if (newciptr->addr) xfree (newciptr->addr);
- xfree (newciptr);
+ free (newciptr->addr);
+ free (newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
@@ -1335,8 +1332,7 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
PRMSG (2, "SocketUNIXAccept(%p,%d)\n", ciptr, ciptr->fd, 0);
- if ((newciptr = (XtransConnInfo) xcalloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((newciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
PRMSG (1, "SocketUNIXAccept: malloc() failed\n", 0, 0, 0);
*status = TRANS_ACCEPT_BAD_MALLOC;
@@ -1347,7 +1343,7 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
(struct sockaddr *) &sockname, (void *)&namelen)) < 0)
{
PRMSG (1, "SocketUNIXAccept: accept() failed\n", 0, 0, 0);
- xfree (newciptr);
+ free (newciptr);
*status = TRANS_ACCEPT_FAILED;
return NULL;
}
@@ -1358,13 +1354,13 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
* since this is unix domain.
*/
- if ((newciptr->addr = (char *) xalloc (ciptr->addrlen)) == NULL)
+ if ((newciptr->addr = malloc (ciptr->addrlen)) == NULL)
{
PRMSG (1,
"SocketUNIXAccept: Can't allocate space for the addr\n",
0, 0, 0);
close (newciptr->fd);
- xfree (newciptr);
+ free (newciptr);
*status = TRANS_ACCEPT_BAD_MALLOC;
return NULL;
}
@@ -1377,14 +1373,14 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
newciptr->addrlen = ciptr->addrlen;
memcpy (newciptr->addr, ciptr->addr, newciptr->addrlen);
- if ((newciptr->peeraddr = (char *) xalloc (ciptr->addrlen)) == NULL)
+ if ((newciptr->peeraddr = malloc (ciptr->addrlen)) == NULL)
{
PRMSG (1,
"SocketUNIXAccept: Can't allocate space for the addr\n",
0, 0, 0);
close (newciptr->fd);
- if (newciptr->addr) xfree (newciptr->addr);
- xfree (newciptr);
+ free (newciptr->addr);
+ free (newciptr);
*status = TRANS_ACCEPT_BAD_MALLOC;
return NULL;
}
@@ -1561,8 +1557,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
PRMSG (4,"SocketINETConnect() Cannot get IPv4 "
" socketfor IPv4 address\n", 0,0,0);
}
- if (newciptr)
- xfree(newciptr);
+ free(newciptr);
} else {
socketaddr = NULL;
PRMSG (4,"SocketINETConnect Skipping IPv4 address\n",
@@ -1599,8 +1594,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
PRMSG (4,"SocketINETConnect() Cannot get IPv6 "
"socket for IPv6 address\n", 0,0,0);
}
- if (newciptr)
- xfree(newciptr);
+ free(newciptr);
}
else
{
@@ -2067,8 +2061,8 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
* since this is unix domain.
*/
- if ((ciptr->addr = (char *) xalloc(namelen)) == NULL ||
- (ciptr->peeraddr = (char *) xalloc(namelen)) == NULL)
+ if ((ciptr->addr = malloc(namelen)) == NULL ||
+ (ciptr->peeraddr = malloc(namelen)) == NULL)
{
PRMSG (1,
"SocketUNIXCreateListener: Can't allocate space for the addr\n",
diff --git a/Xtranstli.c b/Xtranstli.c
index a9dfc21..e50d97f 100644
--- a/Xtranstli.c
+++ b/Xtranstli.c
@@ -166,10 +166,9 @@ TRANS(TLIGetAddr)(XtransConnInfo ciptr)
* Everything looks good: fill in the XtransConnInfo structure.
*/
- if( ciptr->addr )
- xfree(ciptr->addr);
+ free(ciptr->addr);
- if( (ciptr->addr=(char *)xalloc(netbuf.len)) == NULL )
+ if( (ciptr->addr=malloc(netbuf.len)) == NULL )
{
PRMSG(1, "TLIGetAddr: Can't allocate space for the addr\n",
0,0,0);
@@ -216,10 +215,9 @@ TRANS(TLIGetPeerAddr)(XtransConnInfo ciptr)
* Everything looks good: fill in the XtransConnInfo structure.
*/
- if( ciptr->peeraddr )
- xfree(ciptr->peeraddr);
+ free(ciptr->peeraddr);
- if( (ciptr->peeraddr=(char *)xalloc(netbuf.len)) == NULL )
+ if( (ciptr->peeraddr=malloc(netbuf.len)) == NULL )
{
PRMSG(1,
"TLIGetPeerAddr: Can't allocate space for the addr\n",
@@ -316,7 +314,7 @@ TRANS(TLIOpen)(char *device)
PRMSG(3,"TLIOpen(%s)\n", device, 0,0 );
- if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+ if( (ciptr=calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
{
PRMSG(1, "TLIOpen: calloc failed\n", 0,0,0 );
return NULL;
@@ -349,7 +347,7 @@ TRANS(TLIReopen)(char *device, int fd, char *port)
return NULL;
}
- if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+ if( (ciptr=calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
{
PRMSG(1, "TLIReopen: calloc failed\n", 0,0,0 );
return NULL;
@@ -453,7 +451,7 @@ TRANS(TLIOpenCOTSClient)(Xtransport *thistrans, char *protocol,
"TLIOpenCOTSClient: ...TLITLIBindLocal() failed: %d\n",
errno, 0,0 );
t_close(ciptr->fd);
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -463,7 +461,7 @@ TRANS(TLIOpenCOTSClient)(Xtransport *thistrans, char *protocol,
"TLIOpenCOTSClient: ...TLIGetAddr() failed: %d\n",
errno, 0,0 );
t_close(ciptr->fd);
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -553,7 +551,7 @@ TRANS(TLIOpenCLTSClient)(Xtransport *thistrans, char *protocol,
"TLIOpenCLTSClient: ...TLITLIBindLocal() failed: %d\n",
errno, 0,0 );
t_close(ciptr->fd);
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -563,7 +561,7 @@ TRANS(TLIOpenCLTSClient)(Xtransport *thistrans, char *protocol,
"TLIOpenCLTSClient: ...TLIGetPeerAddr() failed: %d\n",
errno, 0,0 );
t_close(ciptr->fd);
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -726,7 +724,7 @@ TRANS(TLICreateListener)(XtransConnInfo ciptr, struct t_bind *req)
* Everything looks good: fill in the XtransConnInfo structure.
*/
- if( (ciptr->addr=(char *)xalloc(ret->addr.len)) == NULL )
+ if( (ciptr->addr=malloc(ret->addr.len)) == NULL )
{
PRMSG(1,
"TLICreateListener: Unable to allocate space for the address\n",
@@ -913,7 +911,7 @@ TRANS(TLIAccept)(XtransConnInfo ciptr, int *status)
errno, 0,0 );
t_free((char *)call,T_CALL);
t_close(newciptr->fd);
- xfree(newciptr);
+ free(newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
@@ -957,7 +955,7 @@ TRANS(TLIAccept)(XtransConnInfo ciptr, int *status)
"TLIAccept: TRANS(TLIGetPeerAddr)() failed: %d\n",
errno, 0,0 );
t_close(newciptr->fd);
- xfree(newciptr);
+ free(newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
@@ -968,8 +966,8 @@ TRANS(TLIAccept)(XtransConnInfo ciptr, int *status)
"TLIAccept: TRANS(TLIGetPeerAddr)() failed: %d\n",
errno, 0,0 );
t_close(newciptr->fd);
- xfree(newciptr->addr);
- xfree(newciptr);
+ free(newciptr->addr);
+ free(newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
@@ -979,8 +977,8 @@ TRANS(TLIAccept)(XtransConnInfo ciptr, int *status)
PRMSG(1, "TLIAccept() ioctl(I_POP, \"timod\") failed %d\n",
errno,0,0 );
t_close(newciptr->fd);
- xfree(newciptr->addr);
- xfree(newciptr);
+ free(newciptr->addr);
+ free(newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
@@ -990,8 +988,8 @@ TRANS(TLIAccept)(XtransConnInfo ciptr, int *status)
PRMSG(1, "TLIAccept() ioctl(I_PUSH,\"tirdwr\") failed %d\n",
errno,0,0 );
t_close(newciptr->fd);
- xfree(newciptr->addr);
- xfree(newciptr);
+ free(newciptr->addr);
+ free(newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
diff --git a/Xtransutil.c b/Xtransutil.c
index 42f09c4..9ec95d2 100644
--- a/Xtransutil.c
+++ b/Xtransutil.c
@@ -197,11 +197,11 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
if (len > 0) {
if (*addrp && *addrlenp < (len + 1))
{
- xfree ((char *) *addrp);
+ free (*addrp);
*addrp = NULL;
}
if (!*addrp)
- *addrp = (Xtransaddr *) xalloc (len + 1);
+ *addrp = malloc (len + 1);
if (*addrp) {
strcpy ((char *) *addrp, hostnamebuf);
*addrlenp = len;
@@ -211,8 +211,7 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
}
else
{
- if (*addrp)
- xfree ((char *) *addrp);
+ free (*addrp);
*addrp = NULL;
*addrlenp = 0;
}
@@ -255,7 +254,7 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr)
case AF_UNIX:
{
struct sockaddr_un *saddr = (struct sockaddr_un *) addr;
- networkId = (char *) xalloc (3 + strlen (transName) +
+ networkId = malloc (3 + strlen (transName) +
strlen (hostnamebuf) + strlen (saddr->sun_path));
sprintf (networkId, "%s/%s:%s", transName,
hostnamebuf, saddr->sun_path);
@@ -285,7 +284,7 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr)
portnum = ntohs (saddr->sin_port);
snprintf (portnumbuf, sizeof(portnumbuf), "%d", portnum);
- networkId = (char *) xalloc (3 + strlen (transName) +
+ networkId = malloc (3 + strlen (transName) +
strlen (hostnamebuf) + strlen (portnumbuf));
sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, portnumbuf);
break;
@@ -418,8 +417,7 @@ TRANS(GetPeerNetworkId) (XtransConnInfo ciptr)
}
- hostname = (char *) xalloc (
- strlen (ciptr->transptr->TransName) + strlen (addr) + 2);
+ hostname = malloc (strlen (ciptr->transptr->TransName) + strlen (addr) + 2);
strcpy (hostname, ciptr->transptr->TransName);
strcat (hostname, "/");
if (addr)
diff --git a/transport.c b/transport.c
index 5131d99..050c8f2 100644
--- a/transport.c
+++ b/transport.c
@@ -52,10 +52,6 @@ from The Open Group.
#include "os.h"
#else
#include <stdlib.h>
-#define xalloc(_size) malloc(_size)
-#define xcalloc(_num,_size) calloc(_num,_size)
-#define xrealloc(_ptr,_size) realloc(_ptr,_size)
-#define xfree(_ptr) free(_ptr)
#endif
#include "Xtransint.h"
--
1.7.1.252.g2c7d
More information about the xorg-devel
mailing list