Skip to content

Commit 41bf7f7

Browse files
author
Felipe Zimmerle
committed
Calls xml init and xml cleanup to avoid memory leak
Fix #1553
1 parent 3036462 commit 41bf7f7

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/modsecurity.cc

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include <ctime>
1717
#include <iostream>
1818

19+
#include <libxml/xmlschemas.h>
20+
#include <libxml/xpath.h>
21+
1922
#include "modsecurity/modsecurity.h"
2023
#include "modsecurity/rule.h"
2124
#include "modsecurity/rule_message.h"
@@ -72,6 +75,7 @@ ModSecurity::ModSecurity()
7275
srand(time(NULL));
7376
#ifdef MSC_WITH_CURL
7477
curl_global_init(CURL_GLOBAL_ALL);
78+
xmlInitParser();
7579
#endif
7680
}
7781

@@ -83,6 +87,8 @@ ModSecurity::~ModSecurity() {
8387
#ifdef WITH_GEOIP
8488
Utils::GeoLookup::getInstance().cleanUp();
8589
#endif
90+
xmlCleanupParser();
91+
8692
delete m_global_collection;
8793
delete m_resource_collection;
8894
delete m_ip_collection;

src/operators/validate_schema.cc

+2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ bool ValidateSchema::evaluate(Transaction *t,
140140
t->debug(4, "XML: Successfully validated payload against " \
141141
"Schema: " + m_resource);
142142
#endif
143+
xmlSchemaFree(m_schema);
144+
xmlSchemaFreeParserCtxt(m_parserCtx);
143145

144146
return false;
145147
}

src/request_body_processor/xml.cc

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ XML::XML(Transaction *transaction)
3333

3434

3535
XML::~XML() {
36+
if (m_data.parsing_ctx != NULL) {
37+
xmlFreeParserCtxt(m_data.parsing_ctx);
38+
m_data.parsing_ctx = NULL;
39+
}
3640
if (m_data.doc != NULL) {
3741
xmlFreeDoc(m_data.doc);
3842
m_data.doc = NULL;

0 commit comments

Comments
 (0)