address and port: reduce memory allocs

pull/663/head
Victor Julien 11 years ago
parent 06f4fe8e0c
commit 2ce8895f0a

@ -600,27 +600,24 @@ int DetectAddressParseString(DetectAddress *dd, char *str)
char *ip2 = NULL;
char *mask = NULL;
int r = 0;
char ipstr[256];
while (*str != '\0' && *str == ' ')
str++;
char *ipdup = SCStrdup(str);
if (unlikely(ipdup == NULL))
return -1;
SCLogDebug("str %s", str);
/* first handle 'any' */
if (strcasecmp(str, "any") == 0) {
dd->flags |= ADDRESS_FLAG_ANY;
SCFree(ipdup);
SCLogDebug("address is \'any\'");
return 0;
}
/* we dup so we can put a nul-termination in it later */
ip = ipdup;
strlcpy(ipstr, str, sizeof(ipstr));
SCLogDebug("str %s", str);
/* we work with a copy so that we can put a
* nul-termination in it later */
ip = ipstr;
/* handle the negation case */
if (ip[0] == '!') {
@ -757,14 +754,11 @@ int DetectAddressParseString(DetectAddress *dd, char *str)
}
SCFree(ipdup);
BUG_ON(dd->ip.family == 0);
return 0;
error:
SCFree(ipdup);
return -1;
}

@ -1402,11 +1402,9 @@ error:
DetectPort *PortParse(char *str) {
char *port2 = NULL;
DetectPort *dp = NULL;
char *portdup = SCStrdup(str);
if (unlikely(portdup == NULL)) {
return NULL;
}
char portstr[16];
strlcpy(portstr, str, sizeof(portstr));
dp = DetectPortInit();
if (dp == NULL)
@ -1415,7 +1413,7 @@ DetectPort *PortParse(char *str) {
/* XXX better input validation */
/* we dup so we can put a nul-termination in it later */
char *port = portdup;
char *port = portstr;
/* handle the negation case */
if (port[0] == '!') {
@ -1457,14 +1455,11 @@ DetectPort *PortParse(char *str) {
}
}
SCFree(portdup);
return dp;
error:
if (dp != NULL)
DetectPortCleanupList(dp);
if (portdup) SCFree(portdup);
return NULL;
}

Loading…
Cancel
Save