Skip to content

Commit

Permalink
Merge pull request #2239 from microsoft/fix_malformed_xml_memory_leak
Browse files Browse the repository at this point in the history
Properly cleanup XML parser contexts upon completion
  • Loading branch information
martinhsv committed Jun 8, 2022
2 parents dd2d3f7 + 6a5ec1f commit fc8e558
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apache2/msc_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ int xml_complete(modsec_rec *msr, char **error_msg) {
* Frees the resources used for XML parsing.
*/
apr_status_t xml_cleanup(modsec_rec *msr) {
if (msr->xml->parsing_ctx != NULL) {
if (msr->xml->parsing_ctx->myDoc) {
xmlFreeDoc(msr->xml->parsing_ctx->myDoc);
}
xmlFreeParserCtxt(msr->xml->parsing_ctx);
msr->xml->parsing_ctx = NULL;
}
if (msr->xml->doc != NULL) {
xmlFreeDoc(msr->xml->doc);
msr->xml->doc = NULL;
Expand Down

0 comments on commit fc8e558

Please sign in to comment.