Looks like net-snmp 5.4 has a memory leak

This is a discussion on Looks like net-snmp 5.4 has a memory leak within the SNMP Coders forums, part of the Networking and Network Related category; This is a multi-part message in MIME format. ------=_NextPart_000_02B6_01C76F08.99BB5100 Content-Type: text/plain; charset="us-ascii" ...


Go Back   Usenet Forums > Networking and Network Related > SNMP Coders

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-26-2007
Luu Vo
 
Posts: n/a
Default Looks like net-snmp 5.4 has a memory leak

This is a multi-part message in MIME format.

------=_NextPart_000_02B6_01C76F08.99BB5100
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hi,

I am experiencing a memory leak and it looks like the cause is in net-snmp
5.4 lib used in my program. I checked net-snmp source code and found that a
buffer was not deleted after use:

File:
net-snmp-5.4\snmplib\snmpUDPDomain.c

Function:
netsnmp_transport *
netsnmp_udp_transport(struct sockaddr_in *addr, int local)

Line:
addr_pair = (netsnmp_udp_addr_pair *)
malloc(sizeof(netsnmp_udp_addr_pair));

The variable addr_pair was not deleted after use. See attached file for the
whole function.

Please advise if this is a bug and need to be fixed.

Thanks,

Luu

------=_NextPart_000_02B6_01C76F08.99BB5100
Content-Type: text/plain;
name="snmpUDPDomain.c.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="snmpUDPDomain.c.txt"

netsnmp_transport *
netsnmp_udp_transport(struct sockaddr_in *addr, int local)
{
netsnmp_transport *t =3D NULL;
int rc =3D 0;
char *str =3D NULL;
char *client_socket =3D NULL;
netsnmp_udp_addr_pair *addr_pair =3D NULL;

if (addr =3D=3D NULL || addr->sin_family !=3D AF_INET) {
return NULL;
}

addr_pair =3D (netsnmp_udp_addr_pair *) =
malloc(sizeof(netsnmp_udp_addr_pair));
if (addr_pair =3D=3D NULL) {
return NULL;
}
memset(addr_pair, 0, sizeof(netsnmp_udp_addr_pair));
memcpy(&(addr_pair->remote_addr), addr, sizeof(struct sockaddr_in));

t =3D (netsnmp_transport *) malloc(sizeof(netsnmp_transport));
if (t =3D=3D NULL) {
return NULL;
}

str =3D netsnmp_udp_fmtaddr(NULL, (void *)addr_pair,=20
sizeof(netsnmp_udp_addr_pair));
DEBUGMSGTL(("netsnmp_udp", "open %s %s:%d\n", local ? "local" : =
"remote",
str,addr->sin_port));
free(str);

memset(t, 0, sizeof(netsnmp_transport));

t->domain =3D netsnmpUDPDomain;
t->domain_length =3D netsnmpUDPDomain_len;

t->sock =3D socket(PF_INET, SOCK_DGRAM, 0);
if (t->sock < 0) {
netsnmp_transport_free(t);
return NULL;
}

_netsnmp_udp_sockopt_set(t->sock, local);

if (local) {
/*
* This session is inteneded as a server, so we must bind on to =
the
* given IP address, which may include an interface address, or =
could
* be INADDR_ANY, but certainly includes a port number.
*/

t->local =3D (u_char *) malloc(6);
if (t->local =3D=3D NULL) {
netsnmp_transport_free(t);
return NULL;
}
memcpy(t->local, (u_char *) & (addr->sin_addr.s_addr), 4);
t->local[4] =3D (htons(addr->sin_port) & 0xff00) >> 8;
t->local[5] =3D (htons(addr->sin_port) & 0x00ff) >> 0;
t->local_length =3D 6;

#if defined(linux) && defined(IP_PKTINFO)
{=20
int sockopt =3D 1;
if (setsockopt(t->sock, SOL_IP, IP_PKTINFO, &sockopt, sizeof =
sockopt) =3D=3D -1) {
DEBUGMSGTL(("netsnmp_udp", "couldn't set IP_PKTINFO: =
%s\n",
strerror(errno)));
return NULL;
}
DEBUGMSGTL(("netsnmp_udp", "set IP_PKTINFO\n"));
}
#endif
rc =3D bind(t->sock, (struct sockaddr *) addr,
sizeof(struct sockaddr));
if (rc !=3D 0) {
netsnmp_udp_close(t);
netsnmp_transport_free(t);
return NULL;
}
t->data =3D NULL;
t->data_length =3D 0;
} else {
/*
* This is a client session. If we've been given a
* client address to send from, then bind to that.
* Otherwise the send will use "something sensible".
*/
client_socket =3D netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
=
NETSNMP_DS_LIB_CLIENT_ADDR);
if (client_socket) {
struct sockaddr_in client_addr;
netsnmp_sockaddr_in2(&client_addr, client_socket, NULL);
client_addr.sin_port =3D 0;
bind(t->sock, (struct sockaddr *)&client_addr,
sizeof(struct sockaddr));
}
/*
* Save the (remote) address in the
* transport-specific data pointer for later use by =
netsnmp_udp_send.
*/

t->data =3D malloc(sizeof(netsnmp_udp_addr_pair));
t->remote =3D (u_char *)malloc(6);
if (t->data =3D=3D NULL || t->remote =3D=3D NULL) {
netsnmp_transport_free(t);
return NULL;
}
memcpy(t->remote, (u_char *) & (addr->sin_addr.s_addr), 4);
t->remote[4] =3D (htons(addr->sin_port) & 0xff00) >> 8;
t->remote[5] =3D (htons(addr->sin_port) & 0x00ff) >> 0;
t->remote_length =3D 6;
memcpy(t->data, addr_pair, sizeof(netsnmp_udp_addr_pair));
t->data_length =3D sizeof(netsnmp_udp_addr_pair);
}

/*
* 16-bit length field, 8 byte UDP header, 20 byte IPv4 header =20
*/

t->msgMaxSize =3D 0xffff - 8 - 20;
t->f_recv =3D netsnmp_udp_recv;
t->f_send =3D netsnmp_udp_send;
t->f_close =3D netsnmp_udp_close;
t->f_accept =3D NULL;
t->f_fmtaddr =3D netsnmp_udp_fmtaddr;

return t;
}

------=_NextPart_000_02B6_01C76F08.99BB5100
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?p...rge&CID=DEVDEV
------=_NextPart_000_02B6_01C76F08.99BB5100
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/...et-snmp-coders

------=_NextPart_000_02B6_01C76F08.99BB5100--



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:06 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0