1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-25 02:50:08 +03:00

feature #282: Thread saefty & memory leaks for XML parsing

This commit is contained in:
Ruben S. Montero 2010-07-29 20:18:02 +02:00
parent f812cce782
commit 7dac88cd32
3 changed files with 28 additions and 13 deletions

View File

@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdexcept>
#include <libxml/parser.h>
#include <signal.h>
#include <unistd.h>
@ -115,6 +116,11 @@ void Nebula::start()
NebulaLog::log("ONE",Log::INFO,os);
// -----------------------------------------------------------
// Initialize the XML library
// -----------------------------------------------------------
xmlInitParser();
// -----------------------------------------------------------
// Pools
// -----------------------------------------------------------
@ -532,6 +538,9 @@ void Nebula::start()
pthread_join(rm->get_thread_id(),0);
pthread_join(hm->get_thread_id(),0);
//XML Library
xmlCleanupParser();
NebulaLog::log("ONE", Log::INFO, "All modules finalized, exiting.\n");
}

View File

@ -485,6 +485,8 @@ int Template::from_xml(const string &xml_str)
}
}
xmlFreeDoc(xml_doc);
return 0;
}

View File

@ -15,7 +15,7 @@ using namespace std;
/* ************************************************************************* */
/* ************************************************************************* */
class TemplateTest : public CppUnit::TestFixture
class TemplateTest : public CppUnit::TestFixture
{
private:
Template *t, *tr, *t1;
@ -32,7 +32,7 @@ public:
TemplateTest()
{
test_ok =
test_ok =
"#This line is a comment\n"
" # Other comment\n"
"MEMORY=345 # more comments behind an attribute\n"
@ -89,6 +89,8 @@ public:
t1= new Template();
t1->parse(test_ok,&error);
xmlInitParser();
}
void tearDown()
@ -96,6 +98,8 @@ public:
delete t;
delete tr;
delete t1;
xmlCleanupParser();
}
/* ********************************************************************* */
@ -108,7 +112,7 @@ public:
string tmp;
rc = t->parse(test_ok,&error);
if ( error != 0 )
{
cerr << error << endl;
@ -139,7 +143,7 @@ public:
CPPUNIT_ASSERT(test_ok_xml == tmp);
}
/* --------------------------------------------------------------------- */
void test_str()
@ -157,21 +161,21 @@ public:
{
vector<Attribute*> attrs;
string *tmp;
CPPUNIT_ASSERT(t1->get("DISK",attrs) == 2 );
CPPUNIT_ASSERT(attrs[0]->type() == Attribute::VECTOR);
tmp = attrs[0]->to_xml();
CPPUNIT_ASSERT( *tmp ==
CPPUNIT_ASSERT( *tmp ==
"<DISK><EXTRA><![CDATA[disk attribute ]]></EXTRA><FILE>"
"<![CDATA[path1]]></FILE></DISK>");
delete tmp;
CPPUNIT_ASSERT(attrs[1]->type() == Attribute::VECTOR);
tmp = attrs[1]->to_xml();
CPPUNIT_ASSERT( *tmp ==
CPPUNIT_ASSERT( *tmp ==
"<DISK><EXTRA><![CDATA[str]]></EXTRA><FILE><![CDATA[path2]]>"
"</FILE><TYPE><![CDATA[disk]]></TYPE></DISK>");
delete tmp;
@ -179,7 +183,7 @@ public:
CPPUNIT_ASSERT(t1->get("CPU",attrs) == 1 );
CPPUNIT_ASSERT(attrs[2]->type() == Attribute::SIMPLE);
tmp = attrs[2]->to_xml();
CPPUNIT_ASSERT( *tmp == "<CPU><![CDATA[4]]></CPU>");
delete tmp;
@ -203,7 +207,7 @@ public:
void test_remove()
{
vector<Attribute*> attrs;
string t1_xml;
string rm_xml="<TEMPLATE><CPU><![CDATA[4]]></CPU><EMPTY_VAR>"
"<![CDATA[]]></EMPTY_VAR><GRAPHICS><PORT><![CDATA[12]]></PORT><VNC>"
@ -235,7 +239,7 @@ public:
"<![CDATA[HOSTNAME = \"host*.com\"]]></REQUIREMENTS><XTRA>"
"<![CDATA[44]]></XTRA></TEMPLATE>";
string xml;
string nattr = "XTRA";
string vattr = "44";
@ -351,7 +355,7 @@ public:
ts->addTest(new CppUnit::TestCaller<TemplateTest>(
"parse() Test",
&TemplateTest::test_parser));
ts->addTest(new CppUnit::TestCaller<TemplateTest>(
"marshall() Test",
&TemplateTest::test_marshall));
@ -395,7 +399,7 @@ public:
int main(int argc, char ** argv)
{
CppUnit::TextUi::TestRunner tr;
tr.addTest(TemplateTest::suite());
tr.run();