Calls xml init and xml cleanup to avoid memory leak

Fix #1553
This commit is contained in:
Felipe Zimmerle 2017-10-10 15:03:50 -03:00
parent 30364628a0
commit 41bf7f716b
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
3 changed files with 12 additions and 0 deletions

View File

@ -16,6 +16,9 @@
#include <ctime>
#include <iostream>
#include <libxml/xmlschemas.h>
#include <libxml/xpath.h>
#include "modsecurity/modsecurity.h"
#include "modsecurity/rule.h"
#include "modsecurity/rule_message.h"
@ -72,6 +75,7 @@ ModSecurity::ModSecurity()
srand(time(NULL));
#ifdef MSC_WITH_CURL
curl_global_init(CURL_GLOBAL_ALL);
xmlInitParser();
#endif
}
@ -83,6 +87,8 @@ ModSecurity::~ModSecurity() {
#ifdef WITH_GEOIP
Utils::GeoLookup::getInstance().cleanUp();
#endif
xmlCleanupParser();
delete m_global_collection;
delete m_resource_collection;
delete m_ip_collection;

View File

@ -140,6 +140,8 @@ bool ValidateSchema::evaluate(Transaction *t,
t->debug(4, "XML: Successfully validated payload against " \
"Schema: " + m_resource);
#endif
xmlSchemaFree(m_schema);
xmlSchemaFreeParserCtxt(m_parserCtx);
return false;
}

View File

@ -33,6 +33,10 @@ XML::XML(Transaction *transaction)
XML::~XML() {
if (m_data.parsing_ctx != NULL) {
xmlFreeParserCtxt(m_data.parsing_ctx);
m_data.parsing_ctx = NULL;
}
if (m_data.doc != NULL) {
xmlFreeDoc(m_data.doc);
m_data.doc = NULL;