Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 20db51d70e6b59a061db97ce9b89c771 > files > 89

net-snmp-5.3.2.2-14.el5.src.rpm

676955 - snmptrapd leaks memory when NetSNMP::TrapReceiver is used for trap handlers

Source: upstream, SVN rev. 19335 and 16983.

diff -up net-snmp-5.3.2.2/perl/TrapReceiver/TrapReceiver.xs.leak1 net-snmp-5.3.2.2/perl/TrapReceiver/TrapReceiver.xs
--- net-snmp-5.3.2.2/perl/TrapReceiver/TrapReceiver.xs.leak1	2006-09-01 22:58:20.000000000 +0200
+++ net-snmp-5.3.2.2/perl/TrapReceiver/TrapReceiver.xs	2011-02-17 15:56:06.620672302 +0100
@@ -39,6 +39,7 @@ int   perl_trapd_handler( netsnmp_pdu   
     size_t ob_len = 0, oo_len = 0;
     AV *varbinds;
     HV *pduinfo;
+    netsnmp_pdu * v2pdu = NULL;
 
     dSP;
     ENTER;
@@ -48,8 +49,10 @@ int   perl_trapd_handler( netsnmp_pdu   
         return 0;
 
     /* nuke v1 PDUs */
-    if (pdu->command == SNMP_MSG_TRAP)
-        pdu = convert_v1pdu_to_v2(pdu);
+    if (pdu->command == SNMP_MSG_TRAP) {
+        v2pdu = convert_v1pdu_to_v2(pdu);
+        pdu = v2pdu;
+    }
 
     cb_data = handler->handler_data;
     if (!cb_data || !cb_data->perl_cb)
@@ -210,12 +213,14 @@ int   perl_trapd_handler( netsnmp_pdu   
 #endif    
     free(tmparray);
 
+    if (v2pdu) {
+        snmp_free_pdu(v2pdu);
+    }
+
     /* Not needed because of the G_DISCARD flag (I think) */
     /* SPAGAIN; */
     /* PUTBACK; */
-#ifndef __x86_64__
-    FREETMPS; /* FIXME: known to cause a segfault on x86-64 */
-#endif
+    FREETMPS;
     LEAVE;
     return NETSNMPTRAPD_HANDLER_OK;
 }