There is a major memory leak in netsnmp_udp_fmtaddr introduced by patch
1775124.

The following is the tail of the valgrind output of the agent when I
started it, ran one (1) snmpwalk 1.3 and then terminated it.

Without the attached patch:

==29157== 35,970 bytes in 3,597 blocks are definitely lost in loss record 4,577 
of 4,578
==29157==    at 0x4024765: malloc (vg_replace_malloc.c:149)
==29157==    by 0x46C444F: strdup (in /lib/libc-2.6.1.so)
==29157==    by 0x426DBEB: netsnmp_udp_fmtaddr (snmpUDPDomain.c:114)
==29157== 
==29157== 35,970 bytes in 3,597 blocks are definitely lost in loss record 4,578 
of 4,578
==29157==    at 0x4024765: malloc (vg_replace_malloc.c:149)
==29157==    by 0x46C444F: strdup (in /lib/libc-2.6.1.so)
==29157==    by 0x426DBEB: netsnmp_udp_fmtaddr (snmpUDPDomain.c:114)
==29157== 
==29157== LEAK SUMMARY:
==29157==    definitely lost: 110,524 bytes in 10,841 blocks.

With the patch:

==27949== LEAK SUMMARY:
==27949==    definitely lost: 2,474 bytes in 40 blocks.

I would like a vote to add it to all branches, and specifically the 5.3
branch.

+1

/MF
Index: trunk/net-snmp/snmplib/snmpUDPDomain.c
===================================================================
--- trunk/net-snmp/snmplib/snmpUDPDomain.c	(revision 16715)
+++ trunk/net-snmp/snmplib/snmpUDPDomain.c	(working copy)
@@ -106,14 +106,14 @@
         to = (struct sockaddr_in *) &(addr_pair->remote_addr);
         if (to == NULL) {
             sprintf(tmp, "UDP: [%s]->unknown",
-                strdup(inet_ntoa(addr_pair->local_addr)));
+                    inet_ntoa(addr_pair->local_addr));
         } else if ( t && t->flags & NETSNMP_TRANSPORT_FLAG_HOSTNAME ) {
             host = gethostbyaddr((char *)to, 4, AF_INET);
             return (host ? strdup(host->h_name) : NULL); 
         } else {
-            sprintf(tmp, "UDP: [%s]->[%s]:%hd",
-                strdup(inet_ntoa(addr_pair->local_addr)),
-                inet_ntoa(to->sin_addr), ntohs(to->sin_port));
+            sprintf(tmp, "UDP: [%s]->", inet_ntoa(addr_pair->local_addr));
+            sprintf(tmp + strlen(tmp), "[%s]:%hd",
+                    inet_ntoa(to->sin_addr), ntohs(to->sin_port));
         }
         return strdup(tmp);
     }
Index: branches/V5-3-patches/net-snmp/snmplib/snmpUDPDomain.c
===================================================================
--- branches/V5-3-patches/net-snmp/snmplib/snmpUDPDomain.c	(revision 16715)
+++ branches/V5-3-patches/net-snmp/snmplib/snmpUDPDomain.c	(working copy)
@@ -102,11 +102,11 @@
         to = (struct sockaddr_in *) &(addr_pair->remote_addr);
         if (to == NULL) {
             sprintf(tmp, "UDP: [%s]->unknown",
-                strdup(inet_ntoa(addr_pair->local_addr)));
+                    inet_ntoa(addr_pair->local_addr));
         } else {
-            sprintf(tmp, "UDP: [%s]->[%s]:%hd",
-                strdup(inet_ntoa(addr_pair->local_addr)),
-                inet_ntoa(to->sin_addr), ntohs(to->sin_port));
+            sprintf(tmp, "UDP: [%s]->", inet_ntoa(addr_pair->local_addr));
+            sprintf(tmp + strlen(tmp), "[%s]:%hd",
+                    inet_ntoa(to->sin_addr), ntohs(to->sin_port));
         }
         return strdup(tmp);
     }
Index: branches/V5-4-patches/net-snmp/snmplib/snmpUDPDomain.c
===================================================================
--- branches/V5-4-patches/net-snmp/snmplib/snmpUDPDomain.c	(revision 16715)
+++ branches/V5-4-patches/net-snmp/snmplib/snmpUDPDomain.c	(working copy)
@@ -105,11 +105,11 @@
         to = (struct sockaddr_in *) &(addr_pair->remote_addr);
         if (to == NULL) {
             sprintf(tmp, "UDP: [%s]->unknown",
-                strdup(inet_ntoa(addr_pair->local_addr)));
+                    inet_ntoa(addr_pair->local_addr));
         } else {
-            sprintf(tmp, "UDP: [%s]->[%s]:%hd",
-                strdup(inet_ntoa(addr_pair->local_addr)),
-                inet_ntoa(to->sin_addr), ntohs(to->sin_port));
+            sprintf(tmp, "UDP: [%s]->", inet_ntoa(addr_pair->local_addr));
+            sprintf(tmp + strlen(tmp), "[%s]:%hd",
+                    inet_ntoa(to->sin_addr), ntohs(to->sin_port));
         }
         return strdup(tmp);
     }
Index: branches/V5-2-patches/net-snmp/snmplib/snmpUDPDomain.c
===================================================================
--- branches/V5-2-patches/net-snmp/snmplib/snmpUDPDomain.c	(revision 16715)
+++ branches/V5-2-patches/net-snmp/snmplib/snmpUDPDomain.c	(working copy)
@@ -99,11 +99,11 @@
         to = (struct sockaddr_in *) &(addr_pair->remote_addr);
         if (to == NULL) {
             sprintf(tmp, "UDP: [%s]->unknown",
-                strdup(inet_ntoa(addr_pair->local_addr)));
+                    inet_ntoa(addr_pair->local_addr));
         } else {
-            sprintf(tmp, "UDP: [%s]->[%s]:%hd",
-                strdup(inet_ntoa(addr_pair->local_addr)),
-                inet_ntoa(to->sin_addr), ntohs(to->sin_port));
+            sprintf(tmp, "UDP: [%s]->", inet_ntoa(addr_pair->local_addr));
+            sprintf(tmp + strlen(tmp), "[%s]:%hd",
+                    inet_ntoa(to->sin_addr), ntohs(to->sin_port));
         }
         return strdup(tmp);
     }
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to