This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

SNMP Agent memory leak fixes


This fixes a memory leak we were seeing.  I just stole the changes from ucd-snmp-4.2.2.


Index: net/snmp/agent/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos-opt/snmp/agent/current/ChangeLog,v
retrieving revision 1.19
diff -u -p -r1.19 ChangeLog
--- net/snmp/agent/current/ChangeLog	3 Jun 2002 16:10:51 -0000	1.19
+++ net/snmp/agent/current/ChangeLog	14 Aug 2002 15:05:00 -0000
@@ -1,3 +1,9 @@
+2002-08-14  David Smith  <dsmith@redhat.com>
+
+	* src/agent_trap.c (send_enterprise_trap_vars):
+	* src/snmp_agent.c (handle_var_list): Memory leak fixes from
+	ucd-snmp-4.2.2.
+
 2002-06-03  Gary Thomas  <gary@chez-thomas.org> (on behalf of)
 2002-06-03  Roland Caßebohm <roland.cassebohm@visionsystems.de>
 
Index: net/snmp/agent/current/src/agent_trap.c
===================================================================
RCS file: /cvs/ecos/ecos-opt/snmp/agent/current/src/agent_trap.c,v
retrieving revision 1.4
diff -u -p -r1.4 agent_trap.c
--- net/snmp/agent/current/src/agent_trap.c	3 Jun 2002 16:10:51 -0000	1.4
+++ net/snmp/agent/current/src/agent_trap.c	14 Aug 2002 15:05:00 -0000
@@ -332,13 +332,17 @@ void send_enterprise_trap_vars (int trap
 		 *  Create a template PDU, ready for sending
 		 */
     template_pdu = snmp_pdu_create( SNMP_MSG_TRAP );
-    if ( template_pdu == NULL )
+    if ( template_pdu == NULL ) {
+		/* Free memory if value stored dynamically */
+	snmp_set_var_value( &enterprise_var, NULL, 0);
 	return;
+    }
     template_pdu->trap_type     = trap;
     template_pdu->specific_type = specific;
     if ( snmp_clone_mem((void **)&template_pdu->enterprise,
 				enterprise, enterprise_length*sizeof(oid))) {
 	snmp_free_pdu( template_pdu );
+	snmp_set_var_value( &enterprise_var, NULL, 0);
 	return;
     }
     template_pdu->enterprise_length = enterprise_length;
@@ -399,6 +403,7 @@ void send_enterprise_trap_vars (int trap
 	case SNMP_TRAP_AUTHFAIL:
                 if (snmp_enableauthentraps == SNMP_AUTHENTICATED_TRAPS_DISABLED) {
                     snmp_free_pdu( template_pdu );
+		    snmp_set_var_value( &enterprise_var, NULL, 0);
 		    return;
                 }
 		snmp_set_var_value( &snmptrap_var,
@@ -458,6 +463,9 @@ void send_enterprise_trap_vars (int trap
 	    last_var->next_variable = NULL;
     }
 
+		/* Free memory if values stored dynamically */
+    snmp_set_var_value( &enterprise_var, NULL, 0);
+    snmp_set_var_value( &snmptrap_var, NULL, 0);
 	/* Ensure we don't free anything we shouldn't */
     if ( last_var )
 	last_var->next_variable = NULL;
Index: net/snmp/agent/current/src/snmp_agent.c
===================================================================
RCS file: /cvs/ecos/ecos-opt/snmp/agent/current/src/snmp_agent.c,v
retrieving revision 1.4
diff -u -p -r1.4 snmp_agent.c
--- net/snmp/agent/current/src/snmp_agent.c	3 Jun 2002 16:10:51 -0000	1.4
+++ net/snmp/agent/current/src/snmp_agent.c	14 Aug 2002 15:05:01 -0000
@@ -721,6 +721,9 @@ statp_loop:
 			   asp->exact, &write_method, asp->pdu, &noSuchObject);
 			   
 	if (statP == NULL && (asp->rw != WRITE || write_method == NULL)) {
+	        /*  Careful -- if the varbind was lengthy, it will have
+		    allocated some memory.  */
+	        snmp_set_var_value(varbind_ptr, NULL, 0);
 	    	varbind_ptr->val.integer   = NULL;
 	    	varbind_ptr->val_len = 0;
 		if ( asp->exact ) {
-- 
David Smith
dsmith@redhat.com
Red Hat, Inc.
http://www.redhat.com
256.217.0141 (direct)
256.837.0057 (fax)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]