diff options
author | Matthieu Herrb <matthieu.herrb@laas.fr> | 2012-01-01 19:38:24 +0100 |
---|---|---|
committer | Matthieu Herrb <matthieu.herrb@laas.fr> | 2012-01-01 19:38:24 +0100 |
commit | 7975759fb293f87286b5b07e6a0ced6bda25b7c7 (patch) | |
tree | 6335bb6c93ff379b552eda66d21ae87fbf326f38 /Xtrans.c | |
parent | b79d224675e115e694428bd528314a41e1650356 (diff) | |
parent | 6086f6c1d0e0a1c9e590879acb2319dea0eb6e96 (diff) |
Merge remote-tracking branch 'origin/master' into obsd
Conflicts:
Xtrans.c
Xtransutil.c
Diffstat (limited to 'Xtrans.c')
-rw-r--r-- | Xtrans.c | 98 |
1 files changed, 41 insertions, 57 deletions
@@ -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; |