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

B #4154: Fix memory leaks (#4443)

(cherry picked from commit 1d79978f261f2fce272cec7c5ace167f534d4d8b)
This commit is contained in:
Pavel Czerný 2020-03-29 15:36:09 +02:00 committed by Ruben S. Montero
parent e11a790fb1
commit 33f2ed61e5
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
11 changed files with 29 additions and 16 deletions

View File

@ -790,7 +790,7 @@ int AclManager::del_rule(
{
lock();
AclRule * rule = new AclRule(-1, user, resource, rights, zone);
AclRule rule(-1, user, resource, rights, zone);
int oid = -1;
bool found = false;
@ -803,7 +803,7 @@ int AclManager::del_rule(
for ( it = index.first; (it != index.second && !found); it++)
{
found = *(it->second) == *rule;
found = *(it->second) == rule;
if (found)
{

View File

@ -775,7 +775,7 @@ void HostShareNUMA::set_monitorization(Template &ht, unsigned int _vt)
std::vector<VectorAttribute *> cores;
ht.remove("CORE", cores);
ht.get("CORE", cores);
for (auto it = cores.begin(); it != cores.end(); ++it)
{
@ -797,7 +797,7 @@ void HostShareNUMA::set_monitorization(Template &ht, unsigned int _vt)
std::vector<VectorAttribute *> pages;
ht.remove("HUGEPAGE", pages);
ht.get("HUGEPAGE", pages);
for (auto it = pages.begin(); it != pages.end(); ++it)
{
@ -822,7 +822,7 @@ void HostShareNUMA::set_monitorization(Template &ht, unsigned int _vt)
std::vector<VectorAttribute *> memory;
ht.remove("MEMORY_NODE", memory);
ht.get("MEMORY_NODE", memory);
for (auto it = memory.begin(); it != memory.end(); ++it)
{

View File

@ -221,11 +221,11 @@ int MarketPlace::insert_replace(SqlDB *db, bool replace, string& error_str)
<< other_u << ")";
}
rc = db->exec_wr(oss);
db->free_str(sql_name);
db->free_str(sql_xml);
rc = db->exec_wr(oss);
return rc;
error_xml:

View File

@ -197,11 +197,11 @@ int MarketPlaceApp::insert_replace(SqlDB *db, bool replace, string& error_str)
<< other_u << ")";
}
rc = db->exec_wr(oss);
db->free_str(sql_name);
db->free_str(sql_xml);
rc = db->exec_wr(oss);
return rc;
error_xml:

View File

@ -221,6 +221,9 @@ int MarketPlaceAppPool::import(const std::string& t64, int mp_id,
if ( !PoolObjectSQL::name_is_valid(app->name, error_str) )
{
error_str = "Cannot generate a valida name for app";
delete app;
return -1;
}
}

View File

@ -184,7 +184,7 @@ extern "C" void * rm_xml_server_loop(void *arg)
// -------------------------------------------------------------------------
// Main connection loop
// -------------------------------------------------------------------------
ConnectionManager *cm =new ConnectionManager(rm, rm->max_conn);
std::unique_ptr<ConnectionManager> cm{new ConnectionManager(rm, rm->max_conn)};
while (true)
{
@ -205,13 +205,11 @@ extern "C" void * rm_xml_server_loop(void *arg)
NebulaLog::log("ReM", Log::DDEBUG, oss);
Connection * rc = new Connection(client_fd, cm);
Connection * rc = new Connection(client_fd, cm.get());
pthread_create(&thread_id, &pattr, rm_do_connection, (void *) rc);
}
delete cm;
return 0;
}

View File

@ -362,6 +362,8 @@ void VirtualNetworkReserve::request_execute(
att.resp_msg = ar.message;
failure_response(AUTHORIZATION, att);
delete vtmpl;
return;
}

View File

@ -58,7 +58,6 @@ void VirtualRouterInstantiate::request_execute(
VMTemplatePool* tpool = nd.get_tpool();
PoolObjectAuth vr_perms;
Template* extra_attrs;
string error;
string vr_name, tmp_name;
ostringstream oss;
@ -82,7 +81,7 @@ void VirtualRouterInstantiate::request_execute(
vr->get_permissions(vr_perms);
extra_attrs = vr->get_vm_template();
std::unique_ptr<Template> extra_attrs{vr->get_vm_template()};
vr_name = vr->get_name();
if (tmpl_id == -1)
@ -146,7 +145,7 @@ void VirtualRouterInstantiate::request_execute(
tmp_name = one_util::gsub(name, "%i", oss.str());
ErrorCode ec = tmpl_instantiate.request_execute(tmpl_id, tmp_name,
true, str_uattrs, extra_attrs, vid, att);
true, str_uattrs, extra_attrs.get(), vid, att);
if (ec != SUCCESS)
{

View File

@ -51,6 +51,7 @@ static std::string get_encoding(MYSQL * c, const std::string& sql,
if ( row == nullptr )
{
error = "Could not read databse encoding";
mysql_free_result(result);
return "";
}

View File

@ -789,6 +789,8 @@ int VirtualMachineDisks::get_images(int vm_id, int uid, const std::string& tsys,
oss << "DISK " << disk_id << ": " << error_str;
error_str = oss.str();
delete disk;
goto error_common;
}
@ -1127,6 +1129,7 @@ VirtualMachineDisk * VirtualMachineDisks::set_up_attach(int vmid, int uid,
dev_prefix, uid, image_id, &snap, true, error);
if ( rc != 0 )
{
delete disk;
return 0;
}
@ -1666,9 +1669,13 @@ int VirtualMachineDisks::check_tm_mad(const string& tm_mad, string& error)
disk_type) != 0 )
{
error = "Image Datastore does not support transfer mode: " + tm_mad;
ds_img->unlock();
return -1;
}
ds_img->unlock();
disk->replace("CLONE_TARGET", clone_target);
disk->replace("LN_TARGET", ln_target);
disk->replace("DISK_TYPE", disk_type);

View File

@ -171,6 +171,7 @@ int AddressRangePool::from_xml_node(const xmlNodePtr node)
if (ar->from_vattr_db(var[i]) != 0)
{
delete ar;
return -1;
}
@ -271,6 +272,8 @@ int AddressRangePool::rm_ars(string& error_msg)
delete ar_template.remove(it->second->attr);
}
delete it->second;
it = ar_pool.erase(it);
}