Hi,

It seems, that there is a memory leak when reconfiguration by SIGHUP signal.

To reproduce and debug the issue I propose the following patch:

diff -rBbNuw -X ../Exclude net-snmp-5.8.org/agent/agent_read_config.c 
net-snmp-5.8/agent/agent_read_config.c
--- net-snmp-5.8.org/agent/agent_read_config.c 2018-07-16 17:33:40.000000000 
+0300
+++ net-snmp-5.8/agent/agent_read_config.c 2019-07-02 10:51:34.219251554 +0300
@@ -304,10 +304,12 @@
 void
 update_config(void)
 {
+    snmp_dump_session_list (__func__, __LINE__);
     snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
                         SNMPD_CALLBACK_PRE_UPDATE_CONFIG, NULL);
     free_config();
     read_configs();
+    snmp_dump_session_list (__func__, __LINE__);
 }


diff -rBbNuw -X ../Exclude net-snmp-5.8.org/include/net-snmp/session_api.h 
net-snmp-5.8/include/net-snmp/session_api.h
--- net-snmp-5.8.org/include/net-snmp/session_api.h 2018-07-16 
17:33:40.000000000 +0300
+++ net-snmp-5.8/include/net-snmp/session_api.h 2019-07-02 10:51:44.091262681 
+0300
@@ -28,6 +28,10 @@
     NETSNMP_IMPORT
     void            snmp_sess_init(netsnmp_session *);

+
+
+    int snmp_dump_session_list (const char * func, int line); /* for debug */
+
     /*
      * netsnmp_session *snmp_open(session)
      *      netsnmp_session *session;
diff -rBbNuw -X ../Exclude net-snmp-5.8.org/snmplib/snmp_api.c 
net-snmp-5.8/snmplib/snmp_api.c
--- net-snmp-5.8.org/snmplib/snmp_api.c 2018-07-16 17:33:40.000000000 +0300
+++ net-snmp-5.8/snmplib/snmp_api.c 2019-07-02 10:50:54.551213214 +0300
@@ -990,6 +990,20 @@
     _init_snmp_init_done = 0;
 }

+int snmp_dump_session_list (const char * func, int line)
+{
+  int indx = 0;
+  struct session_list *slp = Sessions;
+
+  snmp_log(LOG_INFO, "%s(%d) %s Sessions=%p \n", func, line, __func__, 
Sessions);
+
+  for (slp = Sessions; slp; slp = slp->next) {
+    snmp_log(LOG_INFO, "  %d. slp=%p peer=<%s>\n", (int) ++indx, slp, 
slp->session->peername);
+  }
+  return indx;
+}
+
+
 /*
  * inserts session into session list
  */


If some of file snmpd.conf contains the line, for example, 'trapsess -v 2c     
-c public 1.2.3.4" and the process snmpd receives SIGHUP, then in 
/var/log/snmpd.log we see:

...

Reconfiguring daemon

NET-SNMP version 5.8 restarted
update_config(307) snmp_dump_session_list Sessions=0x55aa58c82930
  1. slp=0x55aa58c82930 peer=<(null)>
  2. slp=0x55aa58c73790 peer=<1.2.3.4>
  3. slp=0x55aa58c6bab0 peer=<(null)>
  4. slp=0x55aa58b528d0 peer=<(null)>
update_config(312) snmp_dump_session_list Sessions=0x55aa58c83bf0
  1. slp=0x55aa58c83bf0 peer=<1.2.3.4>
  2. slp=0x55aa58c82930 peer=<(null)>
  3. slp=0x55aa58c73790 peer=<1.2.3.4>
  4. slp=0x55aa58c6bab0 peer=<(null)>
  5. slp=0x55aa58b528d0 peer=<(null)>

...



As a solution, I would suggest the following simple patch:

diff -rBbNuw -X ../Exclude 
net-snmp-5.8.org/agent/mibgroup/notification/snmpNotifyTable_data.c 
net-snmp-5.8/agent/mibgroup/notification/snmpNotifyTable_data.c
--- net-snmp-5.8.org/agent/mibgroup/notification/snmpNotifyTable_data.c 
2018-07-16 17:33:40.000000000 +0300
+++ net-snmp-5.8/agent/mibgroup/notification/snmpNotifyTable_data.c 2019-07-03 
08:17:05.953676342 +0300
@@ -511,6 +511,7 @@
         }
     }
     snmpNotifyTableStorage = NULL;
+    shutdown_snmpTargetAddrEntry_data(); // aru...@advaoptical.com
     return (0);
 }


Thank you, Alex


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

Reply via email to