summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu.herrb@laas.fr>2012-01-01 19:38:24 +0100
committerMatthieu Herrb <matthieu.herrb@laas.fr>2012-01-01 19:38:24 +0100
commit7975759fb293f87286b5b07e6a0ced6bda25b7c7 (patch)
tree6335bb6c93ff379b552eda66d21ae87fbf326f38
parentb79d224675e115e694428bd528314a41e1650356 (diff)
parent6086f6c1d0e0a1c9e590879acb2319dea0eb6e96 (diff)
Merge remote-tracking branch 'origin/master' into obsd
Conflicts: Xtrans.c Xtransutil.c
-rw-r--r--Xtrans.c98
-rw-r--r--Xtranslcl.c55
-rw-r--r--Xtranssock.c65
-rw-r--r--Xtranstli.c38
-rw-r--r--Xtransutil.c15
-rw-r--r--transport.c4
6 files changed, 127 insertions, 148 deletions
diff --git a/Xtrans.c b/Xtrans.c
index c324246..eef4fb9 100644
--- a/Xtrans.c
+++ b/Xtrans.c
@@ -135,15 +135,15 @@ TRANS(FreeConnInfo) (XtransConnInfo ciptr)
prmsg (3,"FreeConnInfo(%p)\n", ciptr);
if (ciptr->addr)
- xfree (ciptr->addr);
+ free (ciptr->addr);
if (ciptr->peeraddr)
- xfree (ciptr->peeraddr);
+ free (ciptr->peeraddr);
if (ciptr->port)
- xfree (ciptr->port);
+ free (ciptr->port);
- xfree ((char *) ciptr);
+ free (ciptr);
}
@@ -213,9 +213,7 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
/* Copy the string so it can be changed */
- len = strlen (address) + 1;
- tmpptr = mybuf = (char *) xalloc (len);
- strlcpy (mybuf, address, len);
+ tmpptr = mybuf = strdup (address);
/* Parse the string to get each component */
@@ -231,7 +229,7 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
*protocol = NULL;
*host = NULL;
*port = NULL;
- xfree (tmpptr);
+ free (tmpptr);
return 0;
}
@@ -281,7 +279,7 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
*protocol = NULL;
*host = NULL;
*port = NULL;
- xfree (tmpptr);
+ free (tmpptr);
return 0;
}
@@ -347,49 +345,41 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
* Now that we have all of the components, allocate new
* string space for them.
*/
- len = strlen (_protocol) + 1;
- if ((*protocol = (char *) xalloc(len)) == NULL)
+
+ if ((*protocol = strdup (_protocol)) == NULL)
{
/* Malloc failed */
*port = NULL;
*host = NULL;
*protocol = NULL;
- xfree (tmpptr);
+ free (tmpptr);
return 0;
}
- else
- strlcpy (*protocol, _protocol, len);
- len = strlen (_host) + 1;
- if ((*host = (char *) xalloc (len)) == NULL)
+ if ((*host = strdup (_host)) == NULL)
{
/* Malloc failed */
*port = NULL;
*host = NULL;
- xfree (*protocol);
+ free (*protocol);
*protocol = NULL;
- xfree (tmpptr);
+ free (tmpptr);
return 0;
- }
- else
- strlcpy (*host, _host, len);
+ }
- len = strlen (_port) + 1;
- if ((*port = (char *) xalloc (len)) == NULL)
+ if ((*port = strdup (_port)) == NULL)
{
/* Malloc failed */
*port = NULL;
- xfree (*host);
+ free (*host);
*host = NULL;
- xfree (*protocol);
+ free (*protocol);
*protocol = NULL;
- xfree (tmpptr);
+ free (tmpptr);
return 0;
}
- else
- strlcpy (*port, _port, len);
- xfree (tmpptr);
+ free (tmpptr);
return 1;
}
@@ -434,9 +424,9 @@ TRANS(Open) (int type, char *address)
prmsg (1,"Open: Unable to find transport for %s\n",
protocol);
- xfree (protocol);
- xfree (host);
- xfree (port);
+ free (protocol);
+ free (host);
+ free (port);
return NULL;
}
@@ -475,17 +465,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;
}
@@ -527,17 +517,14 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
return NULL;
}
-
- len = strlen (port) + 1;
- if ((save_port = (char *) xalloc (len)) == NULL)
+
+ if ((save_port = strdup (port)) == NULL)
{
prmsg (1,"Reopen: Unable to malloc port string\n");
return NULL;
}
- strlcpy (save_port, port, len);
-
/* Get a new XtransConnInfo object */
switch (type)
@@ -555,6 +542,7 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
if (ciptr == NULL)
{
prmsg (1,"Reopen: transport open failed\n");
+ free (save_port);
return NULL;
}
@@ -658,15 +646,11 @@ TRANS(GetReopenInfo) (XtransConnInfo ciptr,
{
*trans_id = Xtransports[i].transport_id;
*fd = ciptr->fd;
-
- len = strlen (ciptr->port) + 1;
- if ((*port = (char *) xalloc (len)) == NULL)
+
+ if ((*port = strdup (ciptr->port)) == NULL)
return 0;
else
- {
- strlcpy (*port, ciptr->port, len);
return 1;
- }
}
return 0;
@@ -851,16 +835,16 @@ TRANS(Connect) (XtransConnInfo ciptr, char *address)
{
prmsg (1,"Connect: Missing port specification in %s\n",
address);
- if (protocol) xfree (protocol);
- if (host) xfree (host);
+ if (protocol) free (protocol);
+ if (host) free (host);
return -1;
}
ret = ciptr->transptr->Connect (ciptr, host, port);
- if (protocol) xfree (protocol);
- if (host) xfree (host);
- if (port) xfree (port);
+ if (protocol) free (protocol);
+ if (host) free (host);
+ if (port) free (port);
return ret;
}
@@ -958,7 +942,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");
return -1;
@@ -978,7 +962,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");
return -1;
@@ -1147,7 +1131,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;
@@ -1245,7 +1229,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 8466ddc..5beef7c 100644
--- a/Xtranslcl.c
+++ b/Xtranslcl.c
@@ -152,7 +152,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");
return 0;
@@ -162,7 +162,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");
- xfree((char *) sunaddr);
+ free((char *) sunaddr);
return 0;
}
strcpy (sunaddr->sun_path, sun_path);
@@ -174,12 +174,11 @@ 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");
- xfree ((char *) sunaddr);
+ free (sunaddr);
ciptr->addr = NULL;
return 0;
@@ -189,7 +188,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");
- xfree((char *) p_sunaddr);
+ free((char *) p_sunaddr);
return 0;
}
strcpy (p_sunaddr->sun_path, peer_sun_path);
@@ -613,7 +612,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");
close(newfd);
*status = TRANS_ACCEPT_BAD_MALLOC;
@@ -623,9 +622,9 @@ 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");
- xfree(newciptr->addr);
+ free(newciptr->addr);
close(newfd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
@@ -885,7 +884,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");
close(str.fd);
@@ -896,10 +895,10 @@ 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");
- xfree(newciptr->addr);
+ free(newciptr->addr);
close(str.fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
@@ -1223,7 +1222,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");
close(fd);
@@ -1237,10 +1236,10 @@ 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");
- xfree(newciptr->addr);
+ free(newciptr->addr);
close(fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
@@ -1671,17 +1670,13 @@ TRANS(LocalInitTransports)(const char *protocol)
if( strcmp(protocol,"local") && strcmp(protocol,"LOCAL") )
{
- workingXLOCAL=freeXLOCAL=(char *)xalloc (strlen (protocol) + 1);
- if (workingXLOCAL)
- strcpy (workingXLOCAL, protocol);
+ workingXLOCAL = freeXLOCAL = strdup (protocol);
}
else {
XLOCAL=(char *)getenv("XLOCAL");
if(XLOCAL==NULL)
XLOCAL=DEF_XLOCAL;
- workingXLOCAL=freeXLOCAL=(char *)xalloc (strlen (XLOCAL) + 1);
- if (workingXLOCAL)
- strcpy (workingXLOCAL, XLOCAL);
+ workingXLOCAL = freeXLOCAL = strdup (XLOCAL);
}
}
@@ -1690,7 +1685,7 @@ TRANS(LocalEndTransports)(void)
{
prmsg(3,"LocalEndTransports()\n");
- xfree(freeXLOCAL);
+ free(freeXLOCAL);
}
#define TYPEBUFSIZE 32
@@ -1815,7 +1810,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,%lu) failed\n",
sizeof(struct _XtransConnInfo));
@@ -1856,7 +1851,7 @@ TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port)
if( ciptr->fd < 0 )
{
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -1889,7 +1884,7 @@ TRANS(LocalOpenServer)(int type, char *protocol, char *host _X_UNUSED, char *por
*/
#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,%lu) failed\n",
sizeof(struct _XtransConnInfo));
@@ -1925,7 +1920,7 @@ TRANS(LocalOpenServer)(int type, char *protocol, char *host _X_UNUSED, char *por
}
}
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -1943,7 +1938,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,%lu) failed\n",
sizeof(struct _XtransConnInfo));
@@ -1972,7 +1967,7 @@ TRANS(LocalReopenServer)(int type, int index, int fd, char *port)
return ciptr;
}
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -2175,7 +2170,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,%lu) failed\n",
sizeof(struct _XtransConnInfo));
@@ -2187,7 +2182,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 f6a0682..5d1e295 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");
@@ -382,7 +382,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");
@@ -404,8 +404,7 @@ TRANS(SocketOpen) (int i, int type)
prmsg (3,"SocketOpen(%d,%d)\n", i, type);
- if ((ciptr = (XtransConnInfo) xcalloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((ciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
prmsg (1, "SocketOpen: malloc failed\n");
return NULL;
@@ -425,7 +424,7 @@ TRANS(SocketOpen) (int i, int type)
prmsg (2, "SocketOpen: socket() failed for %s\n",
Sockettrans2devtab[i].transname);
- xfree ((char *) ciptr);
+ free (ciptr);
return NULL;
}
@@ -459,6 +458,7 @@ TRANS(SocketReopen) (int i _X_UNUSED, int type, int fd, char *port)
XtransConnInfo ciptr;
int portlen;
struct sockaddr *addr;
+ size_t addrlen;
prmsg (3,"SocketReopen(%d,%d,%s)\n", type, fd, port);
@@ -481,8 +481,7 @@ TRANS(SocketReopen) (int i _X_UNUSED, 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");
return NULL;
@@ -490,23 +489,27 @@ TRANS(SocketReopen) (int i _X_UNUSED, int type, int fd, char *port)
ciptr->fd = fd;
- if ((addr = (struct sockaddr *) xcalloc (1, portlen + 2)) == NULL) {
+ addrlen = portlen + offsetof(struct sockaddr, sa_data);
+ if ((addr = calloc (1, addrlen)) == NULL) {
prmsg (1, "SocketReopen: malloc(addr) failed\n");
+ free (ciptr);
return NULL;
}
ciptr->addr = (char *) addr;
- ciptr->addrlen = portlen + 2;
+ ciptr->addrlen = addrlen;
- if ((ciptr->peeraddr = (char *) xcalloc (1, portlen + 2)) == NULL) {
+ if ((ciptr->peeraddr = calloc (1, addrlen)) == NULL) {
prmsg (1, "SocketReopen: malloc(portaddr) failed\n");
+ free (addr);
+ free (ciptr);
return NULL;
}
- ciptr->peeraddrlen = portlen + 2;
+ ciptr->peeraddrlen = addrlen;
/* Initialize ciptr structure as if it were a normally-opened unix socket */
ciptr->flags = TRANS_LOCAL | TRANS_NOUNLINK;
#ifdef BSD44SOCKETS
- addr->sa_len = portlen + 1;
+ addr->sa_len = addrlen;
#endif
addr->sa_family = AF_UNIX;
#ifdef HAS_STRLCPY
@@ -515,7 +518,7 @@ TRANS(SocketReopen) (int i _X_UNUSED, int type, int fd, char *port)
strncpy(addr->sa_data, port, portlen);
#endif
ciptr->family = AF_UNIX;
- memcpy(ciptr->peeraddr, ciptr->addr, sizeof(struct sockaddr));
+ memcpy(ciptr->peeraddr, ciptr->addr, addrlen);
ciptr->port = rindex(addr->sa_data, ':');
if (ciptr->port == NULL) {
if (is_numeric(addr->sa_data)) {
@@ -1135,7 +1138,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");
@@ -1249,8 +1252,7 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
prmsg (2, "SocketINETAccept(%p,%d)\n", ciptr, ciptr->fd);
- if ((newciptr = (XtransConnInfo) xcalloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((newciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
prmsg (1, "SocketINETAccept: malloc failed\n");
*status = TRANS_ACCEPT_BAD_MALLOC;
@@ -1264,7 +1266,7 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
errno = WSAGetLastError();
#endif
prmsg (1, "SocketINETAccept: accept() failed\n");
- xfree (newciptr);
+ free (newciptr);
*status = TRANS_ACCEPT_FAILED;
return NULL;
}
@@ -1291,7 +1293,7 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
prmsg (1,
"SocketINETAccept: ...SocketINETGetAddr() failed:\n");
close (newciptr->fd);
- xfree (newciptr);
+ free (newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
@@ -1301,8 +1303,8 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
prmsg (1,
"SocketINETAccept: ...SocketINETGetPeerAddr() failed:\n");
close (newciptr->fd);
- if (newciptr->addr) xfree (newciptr->addr);
- xfree (newciptr);
+ if (newciptr->addr) free (newciptr->addr);
+ free (newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
@@ -1326,8 +1328,7 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
prmsg (2, "SocketUNIXAccept(%p,%d)\n", ciptr, ciptr->fd);
- if ((newciptr = (XtransConnInfo) xcalloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((newciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
prmsg (1, "SocketUNIXAccept: malloc() failed\n");
*status = TRANS_ACCEPT_BAD_MALLOC;
@@ -1338,7 +1339,7 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
(struct sockaddr *) &sockname, (void *)&namelen)) < 0)
{
prmsg (1, "SocketUNIXAccept: accept() failed\n");
- xfree (newciptr);
+ free (newciptr);
*status = TRANS_ACCEPT_FAILED;
return NULL;
}
@@ -1349,12 +1350,12 @@ 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");
close (newciptr->fd);
- xfree (newciptr);
+ free (newciptr);
*status = TRANS_ACCEPT_BAD_MALLOC;
return NULL;
}
@@ -1367,13 +1368,13 @@ 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");
close (newciptr->fd);
- if (newciptr->addr) xfree (newciptr->addr);
- xfree (newciptr);
+ if (newciptr->addr) free (newciptr->addr);
+ free (newciptr);
*status = TRANS_ACCEPT_BAD_MALLOC;
return NULL;
}
@@ -1551,7 +1552,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
" socketfor IPv4 address\n");
}
if (newciptr)
- xfree(newciptr);
+ free(newciptr);
} else {
socketaddr = NULL;
prmsg (4,"SocketINETConnect Skipping IPv4 address\n");
@@ -1587,7 +1588,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
"socket for IPv6 address\n");
}
if (newciptr)
- xfree(newciptr);
+ free(newciptr);
}
else
{
@@ -2050,8 +2051,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 8601c13..397c946 100644
--- a/Xtranstli.c
+++ b/Xtranstli.c
@@ -167,9 +167,9 @@ TRANS(TLIGetAddr)(XtransConnInfo ciptr)
*/
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");
return -1;
@@ -216,9 +216,9 @@ TRANS(TLIGetPeerAddr)(XtransConnInfo ciptr)
*/
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");
@@ -312,7 +312,7 @@ TRANS(TLIOpen)(char *device)
prmsg(3,"TLIOpen(%s)\n", device);
- if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+ if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
{
prmsg(1, "TLIOpen: calloc failed\n");
return NULL;
@@ -345,7 +345,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");
return NULL;
@@ -448,7 +448,7 @@ TRANS(TLIOpenCOTSClient)(Xtransport *thistrans, char *protocol,
"TLIOpenCOTSClient: ...TLITLIBindLocal() failed: %d\n",
errno);
t_close(ciptr->fd);
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -458,7 +458,7 @@ TRANS(TLIOpenCOTSClient)(Xtransport *thistrans, char *protocol,
"TLIOpenCOTSClient: ...TLIGetAddr() failed: %d\n",
errno);
t_close(ciptr->fd);
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -548,7 +548,7 @@ TRANS(TLIOpenCLTSClient)(Xtransport *thistrans, char *protocol,
"TLIOpenCLTSClient: ...TLITLIBindLocal() failed: %d\n",
errno);
t_close(ciptr->fd);
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -558,7 +558,7 @@ TRANS(TLIOpenCLTSClient)(Xtransport *thistrans, char *protocol,
"TLIOpenCLTSClient: ...TLIGetPeerAddr() failed: %d\n",
errno);
t_close(ciptr->fd);
- xfree(ciptr);
+ free(ciptr);
return NULL;
}
@@ -720,7 +720,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");
@@ -903,7 +903,7 @@ TRANS(TLIAccept)(XtransConnInfo ciptr, int *status)
errno);
t_free((char *)call,T_CALL);
t_close(newciptr->fd);
- xfree(newciptr);
+ free(newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
@@ -947,7 +947,7 @@ TRANS(TLIAccept)(XtransConnInfo ciptr, int *status)
"TLIAccept: TRANS(TLIGetPeerAddr)() failed: %d\n",
errno);
t_close(newciptr->fd);
- xfree(newciptr);
+ free(newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
@@ -958,8 +958,8 @@ TRANS(TLIAccept)(XtransConnInfo ciptr, int *status)
"TLIAccept: TRANS(TLIGetPeerAddr)() failed: %d\n",
errno);
t_close(newciptr->fd);
- xfree(newciptr->addr);
- xfree(newciptr);
+ free(newciptr->addr);
+ free(newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
@@ -969,8 +969,8 @@ TRANS(TLIAccept)(XtransConnInfo ciptr, int *status)
prmsg(1, "TLIAccept() ioctl(I_POP, \"timod\") failed %d\n",
errno);
t_close(newciptr->fd);
- xfree(newciptr->addr);
- xfree(newciptr);
+ free(newciptr->addr);
+ free(newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
return NULL;
}
@@ -980,8 +980,8 @@ TRANS(TLIAccept)(XtransConnInfo ciptr, int *status)
prmsg(1, "TLIAccept() ioctl(I_PUSH,\"tirdwr\") failed %d\n",
errno);
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 b0f1a9f..6c4b09c 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) {
strlcpy ((char *) *addrp, hostnamebuf, len + 1);
*addrlenp = len;
@@ -212,7 +212,7 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
else
{
if (*addrp)
- xfree ((char *) *addrp);
+ free (*addrp);
*addrp = NULL;
*addrlenp = 0;
}
@@ -258,7 +258,7 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr)
struct sockaddr_un *saddr = (struct sockaddr_un *) addr;
len = 3 + strlen (transName) +
strlen (hostnamebuf) + strlen (saddr->sun_path);
- networkId = (char *) xalloc (len);
+ networkId = malloc (len);
snprintf (networkId, len, "%s/%s:%s", transName,
hostnamebuf, saddr->sun_path);
break;
@@ -289,7 +289,7 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr)
snprintf (portnumbuf, sizeof(portnumbuf), "%d", portnum);
len = 3 + strlen (transName) +
strlen (hostnamebuf) + strlen (portnumbuf);
- networkId = (char *) xalloc (len);
+ networkId = malloc (len);
snprintf (networkId, len, "%s/%s:%s", transName, hostnamebuf,
portnumbuf);
break;
@@ -423,9 +423,10 @@ TRANS(GetPeerNetworkId) (XtransConnInfo ciptr)
}
len = strlen (ciptr->transptr->TransName) + strlen (addr) + 2;
- hostname = (char *) xalloc (len);
+ hostname = malloc (len);
strlcpy (hostname, ciptr->transptr->TransName, len);
strlcat (hostname, "/", len);
+
if (addr)
strlcat (hostname, addr, len);
@@ -590,6 +591,7 @@ trans_mkdir(const char *path, int mode)
if (fstat(fd, &fbuf) == -1) {
prmsg(1, "mkdir: ERROR: fstat failed for %s (%d)\n",
path, errno);
+ close(fd);
return -1;
}
/*
@@ -601,6 +603,7 @@ trans_mkdir(const char *path, int mode)
buf.st_ino != fbuf.st_ino) {
prmsg(1, "mkdir: ERROR: inode for %s changed\n",
path);
+ close(fd);
return -1;
}
if (updateOwner && fchown(fd, 0, 0) == 0)
diff --git a/transport.c b/transport.c
index c14057d..2cb8882 100644
--- a/transport.c
+++ b/transport.c
@@ -48,10 +48,6 @@ from The Open Group.
*/
#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)
#define XTRANS_TRANSPORT_C /* used to flag Xtransint.h that it's being used
here, not just #included in another file */