1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-08 20:58:17 +03:00

Fix a problem when attrs where not defined. Prevents memory leaks in Log

git-svn-id: http://svn.opennebula.org/trunk@73 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Rubén S. Montero 2008-07-22 17:51:35 +00:00
parent 663a9c45de
commit 20ac09e4a7
4 changed files with 111 additions and 94 deletions

View File

@ -63,8 +63,6 @@ private:
MessageType log_level; MessageType log_level;
const char * log_file; const char * log_file;
ios_base::openmode log_mode;
}; };
#endif /* _LOG_H_ */ #endif /* _LOG_H_ */

View File

@ -31,13 +31,14 @@ const char Log::error_names[] ={ 'E', 'W', 'I', 'D' };
Log::Log(const string& file_name, Log::Log(const string& file_name,
const MessageType level, const MessageType level,
ios_base::openmode mode): ios_base::openmode mode):
log_level(level) log_level(level),
log_file(0)
{ {
ofstream file; ofstream file;
log_file = strdup(file_name.c_str()); log_file = strdup(file_name.c_str());
file.open(log_file, log_mode); file.open(log_file, mode);
if (file.fail() == true) if (file.fail() == true)
{ {
@ -55,6 +56,10 @@ Log::Log(const string& file_name,
Log::~Log() Log::~Log()
{ {
if ( log_file != 0 )
{
free(log_file);
}
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

View File

@ -235,7 +235,9 @@ int LibVirtDriver::deployment_description(
disk = dynamic_cast<const VectorAttribute *>(attrs[i]); disk = dynamic_cast<const VectorAttribute *>(attrs[i]);
if ( disk == 0 ) if ( disk == 0 )
{
continue; continue;
}
type = disk->vector_value("TYPE"); type = disk->vector_value("TYPE");
source = disk->vector_value("SOURCE"); source = disk->vector_value("SOURCE");
@ -243,7 +245,7 @@ int LibVirtDriver::deployment_description(
ro = disk->vector_value("READONLY"); ro = disk->vector_value("READONLY");
bus = disk->vector_value("BUS"); bus = disk->vector_value("BUS");
if ( source.empty() | target.empty()) if ( source.empty() || target.empty())
{ {
goto error_disk; goto error_disk;
} }
@ -300,7 +302,9 @@ int LibVirtDriver::deployment_description(
nic = dynamic_cast<const VectorAttribute *>(attrs[i]); nic = dynamic_cast<const VectorAttribute *>(attrs[i]);
if ( nic == 0 ) if ( nic == 0 )
{
continue; continue;
}
bridge = nic->vector_value("BRIDGE"); bridge = nic->vector_value("BRIDGE");
@ -349,38 +353,38 @@ int LibVirtDriver::deployment_description(
{ {
graphics = dynamic_cast<const VectorAttribute *>(attrs[0]); graphics = dynamic_cast<const VectorAttribute *>(attrs[0]);
if ( graphics != 0) if ( graphics != 0 )
{ {
type = graphics->vector_value("TYPE"); type = graphics->vector_value("TYPE");
listen = graphics->vector_value("LISTEN"); listen = graphics->vector_value("LISTEN");
port = graphics->vector_value("PORT"); port = graphics->vector_value("PORT");
passwd = graphics->vector_value("PASSWD"); passwd = graphics->vector_value("PASSWD");
}
if ( type == "vnc" || type == "VNC" ) if ( type == "vnc" || type == "VNC" )
{ {
file << "\t\t<graphics type='vnc'"; file << "\t\t<graphics type='vnc'";
if ( !listen.empty() ) if ( !listen.empty() )
{ {
file << " listen='" << listen << "'"; file << " listen='" << listen << "'";
} }
if ( !port.empty() ) if ( !port.empty() )
{ {
file << " port='" << port << "'"; file << " port='" << port << "'";
} }
if ( !passwd.empty() ) if ( !passwd.empty() )
{ {
file << " password='" << passwd << "'"; file << " password='" << passwd << "'";
} }
file << "/>" << endl; file << "/>" << endl;
} }
else else
{ {
vm->log("VMM", Log::WARNING, "Not supported graphics type, ignored."); vm->log("VMM", Log::WARNING, "Not supported graphics type, ignored.");
}
} }
} }
@ -394,23 +398,23 @@ int LibVirtDriver::deployment_description(
{ {
input = dynamic_cast<const VectorAttribute *>(attrs[0]); input = dynamic_cast<const VectorAttribute *>(attrs[0]);
if ( input != 0) if ( input != 0 )
{ {
type = input->vector_value("TYPE"); type = input->vector_value("TYPE");
bus = input->vector_value("BUS"); bus = input->vector_value("BUS");
}
if ( !type.empty() ) if ( !type.empty() )
{
file << "\t\t<input type='" << type << "'";
if ( !bus.empty() )
{ {
file << " bus='" << bus << "'"; file << "\t\t<input type='" << type << "'";
}
}
file << "/>" << endl; if ( !bus.empty() )
{
file << " bus='" << bus << "'";
}
file << "/>" << endl;
}
}
} }
attrs.clear(); attrs.clear();
@ -429,23 +433,23 @@ int LibVirtDriver::deployment_description(
if ( features != 0 ) if ( features != 0 )
{ {
pae = features->vector_value("PAE"); pae = features->vector_value("PAE");
acpi = features->vector_value("ACPI"); acpi = features->vector_value("ACPI");
file << "\t<features>" << endl;
if ( pae == "yes" )
{
file << "\t\t<pae/>" << endl;
}
if ( acpi == "no" )
{
file << "\t\t<acpi/>" << endl;
}
file << "\t</features>" << endl;
} }
file << "\t<features>" << endl;
if ( pae == "yes" )
{
file << "\t\t<pae/>" << endl;
}
if ( acpi == "no" )
{
file << "\t\t<acpi/>" << endl;
}
file << "\t</features>" << endl;
} }
attrs.clear(); attrs.clear();
@ -460,8 +464,12 @@ int LibVirtDriver::deployment_description(
{ {
raw = dynamic_cast<const VectorAttribute *>(attrs[i]); raw = dynamic_cast<const VectorAttribute *>(attrs[i]);
if ( raw != 0 ) if ( raw == 0 )
type = raw->vector_value("TYPE"); {
continue;
}
type = raw->vector_value("TYPE");
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper); transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);

View File

@ -188,14 +188,16 @@ int XenDriver::deployment_description(
{ {
disk = dynamic_cast<const VectorAttribute *>(attrs[i]); disk = dynamic_cast<const VectorAttribute *>(attrs[i]);
if (disk == 0) if ( disk == 0 )
{
continue; continue;
}
source = disk->vector_value("SOURCE"); source = disk->vector_value("SOURCE");
target = disk->vector_value("TARGET"); target = disk->vector_value("TARGET");
ro = disk->vector_value("READONLY"); ro = disk->vector_value("READONLY");
if ( source.empty() | target.empty()) if ( source.empty() || target.empty())
{ {
goto error_disk; goto error_disk;
} }
@ -237,8 +239,10 @@ int XenDriver::deployment_description(
nic = dynamic_cast<const VectorAttribute *>(attrs[i]); nic = dynamic_cast<const VectorAttribute *>(attrs[i]);
if (nic == 0) if ( nic == 0 )
{
continue; continue;
}
file << " '"; file << " '";
@ -279,32 +283,32 @@ int XenDriver::deployment_description(
listen = graphics->vector_value("LISTEN"); listen = graphics->vector_value("LISTEN");
port = graphics->vector_value("PORT"); port = graphics->vector_value("PORT");
passwd = graphics->vector_value("PASSWD"); passwd = graphics->vector_value("PASSWD");
}
if ( type == "vnc" || type == "VNC" ) if ( type == "vnc" || type == "VNC" )
{ {
file << "vfb = ['type=vnc"; file << "vfb = ['type=vnc";
if ( !listen.empty() ) if ( !listen.empty() )
{ {
file << ",vnclisten=" << listen; file << ",vnclisten=" << listen;
} }
if ( !port.empty() ) if ( !port.empty() )
{ {
file << ",vncdisplay=" << port; file << ",vncdisplay=" << port;
} }
if ( !passwd.empty() ) if ( !passwd.empty() )
{ {
file << ",vncpasswd=" << passwd; file << ",vncpasswd=" << passwd;
} }
file <<"']" << endl; file <<"']" << endl;
} }
else else
{ {
vm->log("VMM", Log::WARNING, "Not supported graphics type, ignored."); vm->log("VMM", Log::WARNING, "Not supported graphics type, ignored.");
}
} }
} }
@ -321,7 +325,9 @@ int XenDriver::deployment_description(
raw = dynamic_cast<const VectorAttribute *>(attrs[i]); raw = dynamic_cast<const VectorAttribute *>(attrs[i]);
if ( raw == 0 ) if ( raw == 0 )
{
continue; continue;
}
type = raw->vector_value("TYPE"); type = raw->vector_value("TYPE");