mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-24 21:34:01 +03:00
Prevents memory leak when replacing a template attribute
git-svn-id: http://svn.opennebula.org/one/trunk@432 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
efb64dc516
commit
fd5aed789a
@ -97,15 +97,7 @@ public:
|
||||
* will be freed when the template destructor is called.
|
||||
* @param attr pointer to the attribute
|
||||
*/
|
||||
virtual void set(Attribute * attr)
|
||||
{
|
||||
if ( replace_mode == true )
|
||||
{
|
||||
attributes.erase(attr->name());
|
||||
}
|
||||
|
||||
attributes.insert(make_pair(attr->name(),attr));
|
||||
};
|
||||
virtual void set(Attribute * attr);
|
||||
|
||||
/**
|
||||
* Removes an attribute from the template. The attributes are returned. The
|
||||
|
@ -152,6 +152,29 @@ void Template::marshall(string &str, const char delim)
|
||||
delete attr;
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void Template::set(Attribute * attr)
|
||||
{
|
||||
if ( replace_mode == true )
|
||||
{
|
||||
multimap<string, Attribute *>::iterator i;
|
||||
pair<multimap<string, Attribute *>::iterator,
|
||||
multimap<string, Attribute *>::iterator> index;
|
||||
|
||||
index = attributes.equal_range(attr->name());
|
||||
|
||||
for ( i = index.first; i != index.second; i++)
|
||||
{
|
||||
delete i->second;
|
||||
}
|
||||
|
||||
attributes.erase(attr->name());
|
||||
}
|
||||
|
||||
attributes.insert(make_pair(attr->name(),attr));
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
Loading…
Reference in New Issue
Block a user