First, please keep answers on the list as I don't feel like doing unpaid
snmp consultancy.

On fre, 2007-06-01 at 08:12 -0700, Chris Tojza wrote:
> Magnus,
> Thank you for you answer it clarifies mys understanding of
> snmp_session longevity. However handling of peername is inconsistent
> with other member of this structure namely snmp_session.securityName
> which I allocate with malloc and I do not free it and I do not see it
> leaking with valgrind so net-snmp must call free on this char *.

This does indeed sound curious. Looking at the code I can't see why
in_session.securityName ain't leaked as well. Could you please provide a
minimal test case?

/MF

> Chris
> 
> ----- Original Message ----
> From: Magnus Fromreide <[EMAIL PROTECTED]>
> To: Chris Tojza <[EMAIL PROTECTED]>
> Cc: [email protected]
> Sent: Thursday, May 31, 2007 5:53:21 PM
> Subject: Re: Is peername in snmp_session leaking?
> 
> On tor, 2007-05-31 at 14:29 -0700, Chris Tojza wrote:
> > Running 5.4.1 pre1 with Red Hat patch Fedora core 7 running on 
> >  uname -a
> > Linux dude 2.6.18-1.2849prerel3.0.0_60.44.0 #1 SMP Wed Apr 11 21:23:08 EDT 
> > 2007 i686 i686 i386 GNU/Linux
> > 
> > 
> > Valgrind reports peername as leaking:
> > 
> > ==14039== 48,648 bytes in 3,476 blocks are definitely lost in loss record 
> > 136 of 138
> > ==14039==    at 0x40044F6: malloc (vg_replace_malloc.c:149)
> > ==14039==    by 0x4371298: SnmpMgr::initSession() (SnmpMgr.C:662)
> > ==14039==    by 0x436E896: SnmpMgr::get(std::string const&, 
> > std::map<std::string, std::string, std::less<std::string>, 
> > std::allocator<std::pair<std::string const, std::string> > >&) 
> > (SnmpMgr.C:252)
> > ==14039==    by 0x435CDDD: HostMgr::getSwitchPortInfo(SnmpMgr&, SwitchInv&, 
> > std::string) (HostMgr.C:2085)
> > ==14039==    by 0x4350CB1: HostMgr::snmpGetSwitchInv(std::string const&, 
> > SwitchInv&, std::string) (HostMgr.C:1051)
> > 
> > 
> > The line 662 in SnmpMgr.C assigns peername to:
> >    struct snmp_session    _session;
> > ..................
> >     _peernameP = (char *) malloc(_ipAddress.length() + 1);
> >     strncpy(_peernameP, _ipAddress.c_str(), _ipAddress.length() + 1);
> >    _session.peername = _peernameP;
> > 
> > ..............
> > I do 
> > snmp_sess_close(_sessp);
> > and
> > // The fix in my program
> > // but snmp_sess_close should have deleted peername.
> > if (_peernameP != NULL)
> >             free(_peernameP);
> >     
> > ---------------------
> > snmp_sess_close should have deleted peername.
> > 
> > What do you think?
> 
> I disagree.
> 
> _session is the argument to the "constructor" snmp_sess_open.
> _sessP is the new instance that is created by the call.
> Given this i consider it quite OK that no ownership transfer takes
> place. The fact that there is no ownership transfer also opens up for
> the use of string constants in _session.
> 
> Note that _session could go out of scope just after the call to
> snmp_sess_open as it have fulfilled it's purpose by then.
> 
> /MF



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to