1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-06 12:58:18 +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;
const char * log_file;
ios_base::openmode log_mode;
};
#endif /* _LOG_H_ */

View File

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

View File

@ -235,15 +235,17 @@ int LibVirtDriver::deployment_description(
disk = dynamic_cast<const VectorAttribute *>(attrs[i]);
if ( disk == 0 )
{
continue;
}
type = disk->vector_value("TYPE");
source = disk->vector_value("SOURCE");
target = disk->vector_value("TARGET");
ro = disk->vector_value("READONLY");
bus = disk->vector_value("BUS");
if ( source.empty() | target.empty())
if ( source.empty() || target.empty())
{
goto error_disk;
}
@ -300,8 +302,10 @@ int LibVirtDriver::deployment_description(
nic = dynamic_cast<const VectorAttribute *>(attrs[i]);
if ( nic == 0 )
{
continue;
}
bridge = nic->vector_value("BRIDGE");
if ( bridge.empty() )
@ -349,41 +353,41 @@ int LibVirtDriver::deployment_description(
{
graphics = dynamic_cast<const VectorAttribute *>(attrs[0]);
if ( graphics != 0)
if ( graphics != 0 )
{
type = graphics->vector_value("TYPE");
listen = graphics->vector_value("LISTEN");
port = graphics->vector_value("PORT");
passwd = graphics->vector_value("PASSWD");
}
if ( type == "vnc" || type == "VNC" )
{
file << "\t\t<graphics type='vnc'";
if ( type == "vnc" || type == "VNC" )
{
file << "\t\t<graphics type='vnc'";
if ( !listen.empty() )
{
file << " listen='" << listen << "'";
}
if ( !listen.empty() )
{
file << " listen='" << listen << "'";
}
if ( !port.empty() )
{
file << " port='" << port << "'";
}
if ( !port.empty() )
{
file << " port='" << port << "'";
}
if ( !passwd.empty() )
{
file << " password='" << passwd << "'";
}
if ( !passwd.empty() )
{
file << " password='" << passwd << "'";
}
file << "/>" << endl;
}
else
{
vm->log("VMM", Log::WARNING, "Not supported graphics type, ignored.");
file << "/>" << endl;
}
else
{
vm->log("VMM", Log::WARNING, "Not supported graphics type, ignored.");
}
}
}
attrs.clear();
// ------------------------------------------------------------------------
@ -394,23 +398,23 @@ int LibVirtDriver::deployment_description(
{
input = dynamic_cast<const VectorAttribute *>(attrs[0]);
if ( input != 0)
if ( input != 0 )
{
type = input->vector_value("TYPE");
bus = input->vector_value("BUS");
}
if ( !type.empty() )
{
file << "\t\t<input type='" << type << "'";
if ( !bus.empty() )
type = input->vector_value("TYPE");
bus = input->vector_value("BUS");
if ( !type.empty() )
{
file << " bus='" << bus << "'";
file << "\t\t<input type='" << type << "'";
if ( !bus.empty() )
{
file << " bus='" << bus << "'";
}
file << "/>" << endl;
}
}
file << "/>" << endl;
}
}
attrs.clear();
@ -429,23 +433,23 @@ int LibVirtDriver::deployment_description(
if ( features != 0 )
{
pae = features->vector_value("PAE");
acpi = features->vector_value("ACPI");
pae = features->vector_value("PAE");
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();
@ -460,8 +464,12 @@ int LibVirtDriver::deployment_description(
{
raw = dynamic_cast<const VectorAttribute *>(attrs[i]);
if ( raw != 0 )
type = raw->vector_value("TYPE");
if ( raw == 0 )
{
continue;
}
type = raw->vector_value("TYPE");
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]);
if (disk == 0)
if ( disk == 0 )
{
continue;
}
source = disk->vector_value("SOURCE");
target = disk->vector_value("TARGET");
ro = disk->vector_value("READONLY");
if ( source.empty() | target.empty())
if ( source.empty() || target.empty())
{
goto error_disk;
}
@ -237,9 +239,11 @@ int XenDriver::deployment_description(
nic = dynamic_cast<const VectorAttribute *>(attrs[i]);
if (nic == 0)
if ( nic == 0 )
{
continue;
}
file << " '";
mac = nic->vector_value("MAC");
@ -279,33 +283,33 @@ int XenDriver::deployment_description(
listen = graphics->vector_value("LISTEN");
port = graphics->vector_value("PORT");
passwd = graphics->vector_value("PASSWD");
}
if ( type == "vnc" || type == "VNC" )
{
file << "vfb = ['type=vnc";
if ( !listen.empty() )
{
file << ",vnclisten=" << listen;
}
if ( !port.empty() )
{
file << ",vncdisplay=" << port;
}
if ( type == "vnc" || type == "VNC" )
{
file << "vfb = ['type=vnc";
if ( !listen.empty() )
{
file << ",vnclisten=" << listen;
}
if ( !port.empty() )
{
file << ",vncdisplay=" << port;
}
if ( !passwd.empty() )
{
file << ",vncpasswd=" << passwd;
}
file <<"']" << endl;
}
else
{
vm->log("VMM", Log::WARNING, "Not supported graphics type, ignored.");
}
if ( !passwd.empty() )
{
file << ",vncpasswd=" << passwd;
}
file <<"']" << endl;
}
else
{
vm->log("VMM", Log::WARNING, "Not supported graphics type, ignored.");
}
}
}
attrs.clear();
@ -321,8 +325,10 @@ int XenDriver::deployment_description(
raw = dynamic_cast<const VectorAttribute *>(attrs[i]);
if ( raw == 0 )
{
continue;
}
type = raw->vector_value("TYPE");
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);