changeset 293:838adaba1b2a

Fix memory leak (from David Smith @ Red Hat)
author gthomas
date Wed, 14 Aug 2002 15:18:33 +0000
parents 918b1f4e9403
children 9f49ba9afe89
files packages/net/snmp/agent/current/ChangeLog packages/net/snmp/agent/current/src/agent_trap.c packages/net/snmp/agent/current/src/snmp_agent.c
diffstat 3 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/packages/net/snmp/agent/current/ChangeLog
+++ b/packages/net/snmp/agent/current/ChangeLog
@@ -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>
 
--- a/packages/net/snmp/agent/current/src/agent_trap.c
+++ b/packages/net/snmp/agent/current/src/agent_trap.c
@@ -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;
--- a/packages/net/snmp/agent/current/src/snmp_agent.c
+++ b/packages/net/snmp/agent/current/src/snmp_agent.c
@@ -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 ) {