]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] fixed useless memory allocation in str2net()
authorWilly Tarreau <w@1wt.eu>
Tue, 8 May 2007 16:28:09 +0000 (18:28 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 May 2007 21:23:38 +0000 (23:23 +0200)
It was not necessary anymore to allocate memory in str2net().
Moreover, some calls to free() were missing in case of errors.

include/common/standard.h
src/standard.c

index b15023473081018bd09d6a66d8dee939fd433c52..b150445dd0bc2b9750a6a03f56a6b7da6515ee06 100644 (file)
@@ -80,12 +80,12 @@ extern int ishex(char s);
 struct sockaddr_in *str2sa(char *str);
 
 /*
- * converts <str> to a two struct in_addr* which are locally allocated.
+ * converts <str> 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 <string> replacing all characters tagged in
  * <map> with the hexadecimal representation of their ASCII-code (2 digits)
index 5405aaf80bee8479ffbf4dd055aad094b6f514e0..988dfd751a5ad4492eae12f2c6f5870b7c02ea0d 100644 (file)
@@ -127,21 +127,18 @@ struct sockaddr_in *str2sa(char *str)
 }
 
 /*
- * converts <str> to a two struct in_addr* which are locally allocated.
+ * converts <str> 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;
 }