[AGENT++] agent++: Memory leak in MigGroup

Jochen Katz katz at agentpp.com
Thu Aug 12 21:51:57 CEST 2010


Hi,

> If an object with a certain Oid is added twice to a MibGroup*, the
> items that are added in the *first* registration are leaked.

yes (can be seen from the code). Both objects are stored in the unsorted
list in MibGroup. When adding them to the ordered list of the Mib, the
first object is added and later overwritten with the second object.

> 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.

Yes, because the pointer is still inside the MibGroup list and is used
when Mib::add is called.

> * 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.

Inside MibContext::add there is a check that prevents double
registration for MibLeaf and MibTable objects. But adding a MibGroup
twice is possible.

For the next release, the MibGroup::add and MibContext::add functions
will check for double registrations.

Regards,
  Jochen



More information about the AGENTPP mailing list