Code cleanup: Initialize variables and others good practice

- initialize invalid_countin UrlDecode :: evaluate
- Free resources before the process die (good practice)
This commit is contained in:
Robert Paprocki
2018-04-30 15:25:02 -07:00
committed by Felipe Zimmerle
parent a278bb673a
commit e4c822e663
3 changed files with 10 additions and 6 deletions

View File

@@ -40,7 +40,7 @@ UrlDecode::UrlDecode(std::string action)
std::string UrlDecode::evaluate(std::string value,
Transaction *transaction) {
unsigned char *val = NULL;
int invalid_count;
int invalid_count = 0;
int changed;
val = (unsigned char *) malloc(sizeof(char) * value.size() + 1);

View File

@@ -461,8 +461,11 @@ TreeNode *CPTAddElement(unsigned char *ipdata, unsigned int ip_bitmask, CPTTree
} else {
i_node = CPTCreateNode();
if(i_node == NULL)
if (i_node == NULL) {
free(new_node->prefix);
free(new_node);
return NULL;
}
//i_node->prefix = NULL;
i_node->bit = test_bit;
@@ -480,6 +483,9 @@ TreeNode *CPTAddElement(unsigned char *ipdata, unsigned int ip_bitmask, CPTTree
i_node->netmasks = reinterpret_cast<unsigned char *>(malloc((node->count - i) * sizeof(unsigned char)));
if(i_node->netmasks == NULL) {
free(new_node->prefix);
free(new_node);
free(i_node);
return NULL;
}