Fix segfault in internal tests 85/139785/3
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 20 Jul 2017 09:13:09 +0000 (11:13 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Tue, 1 Aug 2017 14:49:50 +0000 (14:49 +0000)
Unregister libxml2 callbacks in parser destructor.

Change-Id: Ieeeaebc9299df55325612800304c32f55708091c

src/manager/initial-values/parser.cpp

index 6b393d4..4bb0b6a 100644 (file)
@@ -58,6 +58,8 @@ Parser::Parser(const std::string &XML_filename) :
 }
 Parser::~Parser()
 {
+       xmlSetGenericErrorFunc(NULL, NULL);
+       xmlThrDefSetGenericErrorFunc(NULL, NULL);
 }
 
 using SchemaParserCtxt =
@@ -83,6 +85,9 @@ int Parser::Validate(const std::string &XSD_schema)
                return ERROR_INVALID_ARGUMENT;
        }
 
+       xmlSetGenericErrorFunc(this, &Parser::ErrorValidate);
+       xmlThrDefSetGenericErrorFunc(this, &Parser::ErrorValidate);
+
        Schema schema(xmlSchemaParse(parserCtxt.get()), [](xmlSchemaPtr schemaPtr) {
                xmlSchemaFree(schemaPtr);
        });
@@ -102,11 +107,6 @@ int Parser::Validate(const std::string &XSD_schema)
                return ERROR_INTERNAL;
        }
 
-       xmlSetStructuredErrorFunc(NULL, NULL);
-       xmlSetGenericErrorFunc(this, &Parser::ErrorValidate);
-       xmlThrDefSetStructuredErrorFunc(NULL, NULL);
-       xmlThrDefSetGenericErrorFunc(this, &Parser::ErrorValidate);
-
        retCode = xmlSchemaValidateFile(validCtxt.get(), m_XMLfile.c_str(), 0);
 
        if (0 != retCode) {
@@ -126,6 +126,9 @@ int Parser::Parse()
                return ERROR_INVALID_ARGUMENT;
        }
 
+       xmlSetGenericErrorFunc(this, &Parser::Error);
+       xmlThrDefSetGenericErrorFunc(this, &Parser::Error);
+
        int retCode = xmlSAXUserParseFile(&m_saxHandler, this, m_XMLfile.c_str());
 
        if (0 != retCode) {