mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-25 02:50:08 +03:00
feature #2858: Fix minor memory leaks
This commit is contained in:
parent
977fc0d9e3
commit
ab6de3ae02
@ -43,13 +43,13 @@ public:
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Builds the address range set from an array of VectorAttributes. This
|
||||
* function is used to create address ranges.
|
||||
* Builds the address range from a VectorAttribute. This function is used
|
||||
* to create address ranges.
|
||||
* @param ars the vector of address ranges
|
||||
* @param error_msg describing the error
|
||||
* @return 0 on success
|
||||
*/
|
||||
int from_vattr(vector<Attribute *> ars, string& error_msg);
|
||||
int from_vattr(VectorAttribute * ar, string& error_msg);
|
||||
|
||||
/**
|
||||
* Builds the address range set from its XML representation. This function
|
||||
|
@ -265,7 +265,7 @@ private:
|
||||
int cluster_id,
|
||||
const string& cluster_name);
|
||||
|
||||
virtual ~Datastore(){};
|
||||
virtual ~Datastore();
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
|
@ -61,13 +61,21 @@ public:
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Add an address range to the virtual network
|
||||
* Add a set of address ranges to the virtual network
|
||||
* @param ars_tmpl template in the form AR = [TYPE=...,IP=...,SIZE=...].
|
||||
* @param error_msg If the action fails, this message contains the reason.
|
||||
* @return 0 on success
|
||||
*/
|
||||
int add_ar(VirtualNetworkTemplate * ars_tmpl, string& error_msg);
|
||||
|
||||
/**
|
||||
* Adds a set of address ranges
|
||||
* @param var a vector of address ranges
|
||||
* @param error_msg If the action fails, this message contains the reason.
|
||||
* @return 0 on success
|
||||
*/
|
||||
int add_var(vector<Attribute *> &var, string& error_msg);
|
||||
|
||||
/**
|
||||
* Removes an address range from the VNET
|
||||
* @param ar_id of the address range
|
||||
|
@ -68,6 +68,11 @@ Datastore::Datastore(
|
||||
group_u = 1;
|
||||
}
|
||||
|
||||
Datastore::~Datastore()
|
||||
{
|
||||
delete obj_template;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
|
@ -29,7 +29,7 @@ int NebulaTemplate::load_configuration()
|
||||
string aname;
|
||||
Attribute * attr;
|
||||
|
||||
map<string, Attribute *>::iterator iter, j;
|
||||
map<string, Attribute *>::iterator iter, j, prev;
|
||||
|
||||
set_conf_default();
|
||||
|
||||
@ -59,7 +59,10 @@ int NebulaTemplate::load_configuration()
|
||||
else
|
||||
{
|
||||
delete iter->second;
|
||||
conf_default.erase(iter++);
|
||||
|
||||
prev = iter++;
|
||||
|
||||
conf_default.erase(prev);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,39 +35,19 @@ AddressRangePool::~AddressRangePool()
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRangePool::from_vattr(vector<Attribute *> ars, string& error_msg)
|
||||
int AddressRangePool::from_vattr(VectorAttribute* va, string& error_msg)
|
||||
{
|
||||
vector<Attribute *>::iterator it;
|
||||
AddressRange * ar = new AddressRange(next_ar);
|
||||
|
||||
/* -------------------- Init the AR pool ---------------------------- */
|
||||
|
||||
for (it = ars.begin(); it != ars.end(); it++)
|
||||
if (ar->from_vattr(va, error_msg) != 0)
|
||||
{
|
||||
VectorAttribute * va = static_cast<VectorAttribute *>(*it);
|
||||
|
||||
if (va == 0)
|
||||
{
|
||||
error_msg = "Wrong AR format";
|
||||
return -1;
|
||||
}
|
||||
|
||||
AddressRange * ar = new AddressRange(next_ar);
|
||||
|
||||
if (ar->from_vattr(va, error_msg) != 0)
|
||||
{
|
||||
delete ar;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ar_pool.insert(make_pair(next_ar++, ar));
|
||||
delete ar;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ---------------------- Template ---------------------------------- */
|
||||
ar_pool.insert(make_pair(next_ar++, ar));
|
||||
|
||||
for (it = ars.begin(); it != ars.end(); it++)
|
||||
{
|
||||
ar_template.set(*it);
|
||||
}
|
||||
ar_template.set(va);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
|
||||
|
||||
remove_template_attribute("AR", ars);
|
||||
|
||||
if (ar_pool.from_vattr(ars, error_str) != 0)
|
||||
if (add_var(ars, error_str) != 0)
|
||||
{
|
||||
goto error_ar;
|
||||
}
|
||||
@ -587,23 +587,42 @@ int VirtualNetwork::nic_attribute(
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetwork::add_ar(VirtualNetworkTemplate * ars_tmpl, string& error_msg)
|
||||
int VirtualNetwork::add_var(vector<Attribute *> &var, string& error_msg)
|
||||
{
|
||||
vector<Attribute *> tmp_ars;
|
||||
vector<Attribute *> ars;
|
||||
|
||||
vector<Attribute *>::iterator it;
|
||||
|
||||
ars_tmpl->get("AR", tmp_ars);
|
||||
|
||||
for (it=tmp_ars.begin(); it!=tmp_ars.end(); it++)
|
||||
for (vector<Attribute *>::iterator it=var.begin(); it!=var.end(); it++)
|
||||
{
|
||||
VectorAttribute * var = static_cast<VectorAttribute *>(*it);
|
||||
VectorAttribute * oar = static_cast<VectorAttribute *>(*it);
|
||||
|
||||
ars.push_back(var->clone());
|
||||
if (oar == 0)
|
||||
{
|
||||
error_msg = "Invalid format for address range";
|
||||
return -1;
|
||||
}
|
||||
|
||||
VectorAttribute * ar = oar->clone();
|
||||
|
||||
if (ar_pool.from_vattr(ar, error_msg) != 0)
|
||||
{
|
||||
delete ar;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return ar_pool.from_vattr(ars, error_msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetwork::add_ar(VirtualNetworkTemplate * ars_tmpl, string& error_msg)
|
||||
{
|
||||
vector<Attribute *> var;
|
||||
|
||||
if (ars_tmpl->get("AR", var) > 0)
|
||||
{
|
||||
return add_var(var, error_msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
Loading…
x
Reference in New Issue
Block a user