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

From: Shvedko Pavel (shved@mtu.ru)
Date: Thu Mar 21 2002 - 02:22:51 PST


"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 ---------------
> void CflowdConfig::Clear()
> {
> if (this->_ciscoMap.size() > 0) {
> for (CflowdCiscoMap::iterator iterCisco = this->_ciscoMap.begin();
> iterCisco != this->_ciscoMap.end(); iterCisco++ ) {
>
> delete( (*iterCisco).second );
> }
>
> 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) {
> for (CflowdCollectorMap::iterator iterCollct =
> this->_collectorMap.begin();
> iterCollct != this->_collectorMap.end(); iterCollct++ ) {
>
> delete( (*iterCollct).second );
> }
>
> this->_collectorMap.erase(this->_collectorMap.begin(),
> this->_collectorMap.end());
> }
> return;
> }
>
> 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

P.S. We are by the way familiar! Very much for a long time we worked in
"Sitek" company.

>
> --
> Good luck!
> Nicholas L. Nigay
>
> _______________________________________________
> Cflowd mailing list
> Cflowd@caida.org
> http://login.caida.org/mailman/listinfo/cflowd



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