Remove a temporary raw allocation.
This commit is contained in:
+5
-7
@@ -146,7 +146,7 @@ static std::string Hsts_parse_attr(const char **header_str)
|
||||
/**
|
||||
* Get the value in *header_str.
|
||||
*/
|
||||
static char *Hsts_parse_value(const char **header_str)
|
||||
static std::string Hsts_parse_value(const char **header_str)
|
||||
{
|
||||
uint_t len;
|
||||
const char *str;
|
||||
@@ -167,7 +167,7 @@ static char *Hsts_parse_value(const char **header_str)
|
||||
str = *header_str;
|
||||
len = 0;
|
||||
}
|
||||
return dStrndup(str, len);
|
||||
return std::string{ str, str + len };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,22 +199,20 @@ void a_Hsts_set(const char *header, const DilloUrl *url)
|
||||
/* Iterate until there is nothing left of the string */
|
||||
while (*header) {
|
||||
std::string attr;
|
||||
char *value;
|
||||
|
||||
/* Get attribute */
|
||||
attr = Hsts_parse_attr(&header);
|
||||
|
||||
/* Get the value for the attribute and store it */
|
||||
if (dStrAsciiCasecmp(attr.c_str(), "max-age") == 0) {
|
||||
value = Hsts_parse_value(&header);
|
||||
if (isdigit(*value)) {
|
||||
auto value = Hsts_parse_value(&header);
|
||||
if (isdigit(*value.c_str())) {
|
||||
errno = 0;
|
||||
max_age = strtol(value, NULL, 10);
|
||||
max_age = strtol(value.c_str(), NULL, 10);
|
||||
if (errno == ERANGE)
|
||||
max_age = INT_MAX;
|
||||
max_age_valid = TRUE;
|
||||
}
|
||||
dFree(value);
|
||||
} else if (dStrAsciiCasecmp(attr.c_str(), "includeSubDomains") == 0) {
|
||||
subdomains = TRUE;
|
||||
Hsts_eat_value(&header);
|
||||
|
||||
Reference in New Issue
Block a user