Removes some memory leaks

This commit is contained in:
Felipe Zimmerle 2015-10-30 17:24:39 -03:00
parent 061ba0131a
commit 48704c27a9
8 changed files with 36 additions and 5 deletions

View File

@ -683,6 +683,12 @@ int Assay::processRequestBody() {
std::string(a->m_key, 16, a->m_key.length() - 16) + ": " \
+ a->m_value + "\n";
}
while (l.empty() == false) {
delete l.front();
l.pop_front();
}
fullRequest = fullRequest + "\n\n";
fullRequest = fullRequest + m_requestBody.str();
m_collections.store("FULL_REQUEST", fullRequest);

View File

@ -87,16 +87,18 @@ bool Pm::evaluate(Assay *assay, const std::string &input) {
bool Pm::init(const std::string &file, const char **error) {
std::vector<std::string> vec;
std::istringstream *iss;
replaceAll(param, "\\", "\\\\");
char *content = parse_pm_content(param.c_str(), param.length(), error);
if (content == NULL) {
return false;
iss = new std::istringstream(param);
} else {
iss = new std::istringstream(content);
}
std::istringstream iss(param);
std::copy(std::istream_iterator<std::string>(iss),
std::copy(std::istream_iterator<std::string>(*iss),
std::istream_iterator<std::string>(),
back_inserter(vec));
@ -106,6 +108,13 @@ bool Pm::init(const std::string &file, const char **error) {
acmp_prepare(m_p);
if (content) {
free(content);
content = NULL;
}
delete iss;
return true;
}

View File

@ -42,6 +42,7 @@ bool PmFromFile::init(const std::string &config, const char **error) {
if (((std::ifstream *)iss)->is_open() == false) {
*error = std::string("Failed to open file: " + param).c_str();
delete iss;
return false;
}
}
@ -52,6 +53,7 @@ bool PmFromFile::init(const std::string &config, const char **error) {
acmp_prepare(m_p);
delete iss;
return true;
}

View File

@ -420,6 +420,7 @@ expression:
if (phase != NULL) {
definedPhase = phase->phase;
secRuleDefinedPhase = phase->m_secRulesPhase;
delete phase;
} else if (a->action_kind == Action::RunTimeOnlyIfMatchKind ||
a->action_kind == Action::RunTimeBeforeMatchAttemptKind) {
None *none = dynamic_cast<None *>(a);
@ -449,6 +450,8 @@ expression:
for (Action *a : checkedActions) {
driver.defaultActions[definedPhase].push_back(a);
}
delete actions;
}
| CONFIG_DIR_SEC_MARKER
{

View File

@ -290,6 +290,7 @@ bool Rule::evaluate(Assay *assay) {
exclusions.push_back(y->m_key);
}
exclusions.push_back(variable->name);
delete z;
}
}
@ -495,6 +496,7 @@ bool Rule::evaluate(Assay *assay) {
delete e->front();
e->pop_front();
}
delete e;
}
return ret;
}

View File

@ -88,7 +88,6 @@ std::vector<std::string> split(std::string str, char delimiter) {
double random_number(const double from, const double to) {
std::random_device rd;
return std::bind(
std::uniform_real_distribution<>{from, to},
std::default_random_engine{ rd() })();
@ -1064,16 +1063,20 @@ std::string find_resource(const std::string& resource,
iss = new std::ifstream(resource, std::ios::in);
if (iss->is_open()) {
iss->close();
delete iss;
return resource;
}
delete iss;
// Trying the same path of the configuration file.
std::string f = get_path(config) + "/" + resource;
iss = new std::ifstream(f, std::ios::in);
if (iss->is_open()) {
iss->close();
delete iss;
return f;
}
delete iss;
return std::string("");
}

View File

@ -41,6 +41,12 @@ std::list<transaction::Variable *> *
count++;
}
while (reslIn->empty() == false) {
delete reslIn->front();
reslIn->pop_front();
}
delete reslIn;
std::string res = std::to_string(count);
reslOut->push_back(new transaction::Variable(std::string(var->name),

@ -1 +1 @@
Subproject commit 37cf32eb8f939c06923a9ab24dd56a0975c36d4a
Subproject commit e16ceb6ed48dc5af3206220c3c8945def204b9b7