[AGENT++] agent++: Memory leak in MigGroup
dominik.vogt at external.thalesgroup.com
dominik.vogt at external.thalesgroup.com
Thu Aug 12 15:03:44 CEST 2010
On Wed, Aug 11, 2010 at 03:29:39PM +0200, Dominik Vogt wrote:
> On Wed, Aug 11, 2010 at 03:21:05PM +0200, Frank Fock wrote:
> > The first is a memory leak (when the objects in the group could not
> be
> > added). This have to be fixed. The other is not a leak and is
> intended
> > behavior. The Mib class is always responsible for deleting MibEntry
> > objects.
>
> The Mib class *does not* delete the items in the MibGroup.
> Valgrind reports the memory to be leaked by losing the last
> reference to the memory when the Mib is deleted.
Allright, this is what happens:
If an object with a certain Oid is added twice to a MibGroup*, the
items that are added in the *first* registration are leaked. The
leak can be seen with this group definition:
struct foo : public MibGroup
{
foo();
};
foo::foo()
: MibGroup("1.3.6.1.2.1.1", "systemGroup")
{
MibEntry *p1;
MibEntry *p2;
add((p1 = new sysDescr("bar")));
add((p2 = new sysDescr("bar")));
}
With this snippet of code, the memory referenced by *p1*,
allocated with the first call of new, is lost. However, if I add
delete p1;
at the end of the function, memory gets corrupted. Deep
investigations into the memory structures stored in the Mib object
have shown me that a mix of memory allocated by the first and the
second new is stored in the Mib object. There must be something
wrong in the code that checks if a certain oid already exists in
the Mib object.
Ciao
Dominik ^_^ ^_^
* Note: Similar memory corruption may happen if simple MibEntry
objects with the same oid are added to the mid; I did not test
that case.
--
Doominik Vogt
More information about the AGENTPP
mailing list