Fixed possible memory leaks in dbfwfilter.c
Made some variables stack allocated so there is no change of memory leaking. There was no real reason to allocate memory from the heap for the variables in question since they did not need to persist outside the scope of the function.
This commit is contained in:
@ -989,7 +989,7 @@ bool parse_rule_definition(FW_INSTANCE* instance, RULE* ruledef, char* rule, cha
|
|||||||
{
|
{
|
||||||
bool escaped = false;
|
bool escaped = false;
|
||||||
regex_t *re;
|
regex_t *re;
|
||||||
char* start, *str;
|
char* start;
|
||||||
tok = strtok_r(NULL, " ", saveptr);
|
tok = strtok_r(NULL, " ", saveptr);
|
||||||
char delim = '\'';
|
char delim = '\'';
|
||||||
int n_char = 0;
|
int n_char = 0;
|
||||||
@ -1042,20 +1042,13 @@ bool parse_rule_definition(FW_INSTANCE* instance, RULE* ruledef, char* rule, cha
|
|||||||
goto retblock;
|
goto retblock;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = calloc(((tok - start) + 1), sizeof(char));
|
char str[(tok - start) + 1];
|
||||||
if (str == NULL)
|
|
||||||
{
|
|
||||||
MXS_ERROR("Fatal Error: malloc returned NULL.");
|
|
||||||
rval = false;
|
|
||||||
goto retblock;
|
|
||||||
}
|
|
||||||
re = (regex_t*) malloc(sizeof(regex_t));
|
re = (regex_t*) malloc(sizeof(regex_t));
|
||||||
|
|
||||||
if (re == NULL)
|
if (re == NULL)
|
||||||
{
|
{
|
||||||
MXS_ERROR("Fatal Error: malloc returned NULL.");
|
MXS_ERROR("Fatal Error: malloc returned NULL.");
|
||||||
rval = false;
|
rval = false;
|
||||||
free(str);
|
|
||||||
goto retblock;
|
goto retblock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1073,7 +1066,6 @@ bool parse_rule_definition(FW_INSTANCE* instance, RULE* ruledef, char* rule, cha
|
|||||||
ruledef->type = RT_REGEX;
|
ruledef->type = RT_REGEX;
|
||||||
ruledef->data = (void*) re;
|
ruledef->data = (void*) re;
|
||||||
}
|
}
|
||||||
free(str);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (strcmp(tok, "limit_queries") == 0)
|
else if (strcmp(tok, "limit_queries") == 0)
|
||||||
@ -1267,11 +1259,8 @@ createInstance(char **options, FILTER_PARAMETER **params)
|
|||||||
{
|
{
|
||||||
if (strcmp(params[i]->name, "rules") == 0)
|
if (strcmp(params[i]->name, "rules") == 0)
|
||||||
{
|
{
|
||||||
if (filename)
|
filename = params[i]->value;
|
||||||
{
|
break;
|
||||||
free(filename);
|
|
||||||
}
|
|
||||||
filename = strdup(params[i]->value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1282,6 +1271,7 @@ createInstance(char **options, FILTER_PARAMETER **params)
|
|||||||
if (strcmp(options[i], "ignorecase") == 0)
|
if (strcmp(options[i], "ignorecase") == 0)
|
||||||
{
|
{
|
||||||
my_instance->regflags |= REG_ICASE;
|
my_instance->regflags |= REG_ICASE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1300,7 +1290,6 @@ createInstance(char **options, FILTER_PARAMETER **params)
|
|||||||
MXS_ERROR("Error while opening rule file for firewall filter.");
|
MXS_ERROR("Error while opening rule file for firewall filter.");
|
||||||
hashtable_free(my_instance->htable);
|
hashtable_free(my_instance->htable);
|
||||||
free(my_instance);
|
free(my_instance);
|
||||||
free(filename);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1350,16 +1339,15 @@ createInstance(char **options, FILTER_PARAMETER **params)
|
|||||||
if (file_empty)
|
if (file_empty)
|
||||||
{
|
{
|
||||||
MXS_ERROR("dbfwfilter: File is empty: %s", filename);
|
MXS_ERROR("dbfwfilter: File is empty: %s", filename);
|
||||||
free(filename);
|
|
||||||
err = true;
|
err = true;
|
||||||
goto retblock;
|
goto retblock;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
free(filename);
|
|
||||||
|
|
||||||
/**Apply the rules to users*/
|
/**Apply the rules to users*/
|
||||||
ptr = my_instance->userstrings;
|
ptr = my_instance->userstrings;
|
||||||
|
my_instance->userstrings = NULL;
|
||||||
|
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
{
|
{
|
||||||
@ -2182,6 +2170,10 @@ bool parse_at_times(const char** tok, char** saveptr, RULE* ruledef)
|
|||||||
{
|
{
|
||||||
ruledef->active = tr;
|
ruledef->active = tr;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
free(tr);
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user