From: Willy Tarreau Date: Tue, 8 May 2007 16:28:09 +0000 (+0200) Subject: [MINOR] fixed useless memory allocation in str2net() X-Git-Tag: v1.3.10~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d077a8e67c3e28a72e70c70427dc9944f6ec3b9f;p=thirdparty%2Fhaproxy.git [MINOR] fixed useless memory allocation in str2net() It was not necessary anymore to allocate memory in str2net(). Moreover, some calls to free() were missing in case of errors. --- diff --git a/include/common/standard.h b/include/common/standard.h index b150234730..b150445dd0 100644 --- a/include/common/standard.h +++ b/include/common/standard.h @@ -80,12 +80,12 @@ extern int ishex(char s); struct sockaddr_in *str2sa(char *str); /* - * converts to a two struct in_addr* which are locally allocated. + * converts to two struct in_addr* which must be pre-allocated. * The format is "addr[/mask]", where "addr" cannot be empty, and mask * is optionnal and either in the dotted or CIDR notation. * Note: "addr" can also be a hostname. Returns 1 if OK, 0 if error. */ -int str2net(char *str, struct in_addr *addr, struct in_addr *mask); +int str2net(const char *str, struct in_addr *addr, struct in_addr *mask); /* will try to encode the string replacing all characters tagged in * with the hexadecimal representation of their ASCII-code (2 digits) diff --git a/src/standard.c b/src/standard.c index 5405aaf80b..988dfd751a 100644 --- a/src/standard.c +++ b/src/standard.c @@ -127,21 +127,18 @@ struct sockaddr_in *str2sa(char *str) } /* - * converts to a two struct in_addr* which are locally allocated. + * converts to two struct in_addr* which must be pre-allocated. * The format is "addr[/mask]", where "addr" cannot be empty, and mask * is optionnal and either in the dotted or CIDR notation. * Note: "addr" can also be a hostname. Returns 1 if OK, 0 if error. */ -int str2net(char *str, struct in_addr *addr, struct in_addr *mask) +int str2net(const char *str, struct in_addr *addr, struct in_addr *mask) { char *c; unsigned long len; memset(mask, 0, sizeof(*mask)); memset(addr, 0, sizeof(*addr)); - str = strdup(str); - if (str == NULL) - return 0; if ((c = strrchr(str, '/')) != NULL) { *c++ = '\0'; @@ -173,7 +170,6 @@ int str2net(char *str, struct in_addr *addr, struct in_addr *mask) else *addr = *(struct in_addr *) *(he->h_addr_list); } - free(str); return 1; }