Re: [Cflowd] [Fwd: Fix for memory leak on each config re-read.]

From: Nicholas L. Nigay (nnigay@cboss.ru)
Date: Thu Mar 21 2002 - 05:16:16 PST


Hello, Pavel !

Seems You were right about my previous way to solve memory leak problem.
The following decision is aware about several pointers
'looking' at the same place since it uses CflowdCiscoMap::Clear()
and CflowdCollectorMap::Clear() which are correct.

I think that CflowdCollectorMap::Clear() is correct since it
calls delete() only once per 'COLLECTOR stanza' when
((*collmIter).first == (*(*collmIter).second).IpAddress()).

The same idea is in CflowdCiscoMap::Clear().

void CflowdConfig::Clear()
{
   if (this->_ciscoMap.size() > 0) {
     this->_ciscoMap.Clear();
   }

   if (this->_portList.size() > 0)
     this->_portList.erase(this->_portList.begin(),this->_portList.end());

   if (this->_collectorMap.size() > 0) {
     this->_collectorMap.Clear();
   }
   return;
}

PS: I suppose we talking about cflowd-2-1-b1
PPS: Hope this time no bugs. 8-)

Shvedko Pavel wrote:
> "Nicholas L. Nigay" wrote:
>
>
>>There are a few amount of memory new()-ed in LoadConfigFile().
>>But not all of them are freed.
>>It causes memory leak each time config is re-readed.
>>
>>in CflowdConfig.cc ( or CflowdConfig.cc.in if you prefer ):
>>
>>// ---------------- wrong : causes memory leak ------------
>>void CflowdConfig::Clear()
>>{
>> if (this->_ciscoMap.size() > 0)
>> this->_ciscoMap.erase(this->_ciscoMap.begin(),this->_ciscoMap.end());
>> if (this->_portList.size() > 0)
>> this->_portList.erase(this->_portList.begin(),this->_portList.end());
>> if (this->_collectorMap.size() > 0)
>> this->_collectorMap.erase(this->_collectorMap.begin(),
>> this->_collectorMap.end());
>>
>> return;
>>}
>>
>>// ----------------- looks correct : no memory leak ---------------
[skipped, since it were wrong]
>>
>>PS: Please, let me know if i was wrong.
>>
>
>
> Greetings Nikolay!
> Excuse but you too are mistaken!
> Simply look on CflowdCiscoMap::ólear() and all you will understand.
> But it is impossible to use incorrect method CflowdCollectorMap::Clear(),
> it should be just as CflowdCiscoMap::Clear() because of cross pointer links of
> CflowdCollector.
>
> Good luck!
> Shvedko Pavel
>

-- 
Good luck!
Nicholas L. Nigay


This archive was generated by hypermail 2.1.4 : Mon Mar 25 2002 - 11:16:01 PST