From fbdfba2509bd1a4e255fef7448bb18f7afd41b5c Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 7 Jan 2016 09:52:13 +0100 Subject: [PATCH] SNMP: Found the correct cause of a memory leak --- src/apps/snmp/snmp_msg.c | 12 +++++++++--- src/apps/snmp/snmp_threadsync.c | 18 +++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index 88be019e..cc2c1be9 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -244,6 +244,12 @@ snmp_process_varbind(struct snmp_request *request, struct snmp_varbind *vb, u8_t if (request->error_status == SNMP_ERR_NOERROR) { /* use 'getnext_validate' method for validation to avoid code duplication (some checks have to be executed here) */ request->error_status = snmp_msg_getnext_validate_node_inst(&node_instance, request); + + if (request->error_status != SNMP_ERR_NOERROR) { + if (node_instance.release_instance != NULL) { + node_instance.release_instance(&node_instance); + } + } } } @@ -280,10 +286,10 @@ snmp_process_varbind(struct snmp_request *request, struct snmp_varbind *vb, u8_t } else if (err != ERR_OK) { request->error_status = SNMP_ERR_GENERROR; } - } - if (node_instance.release_instance != NULL) { - node_instance.release_instance(&node_instance); + if (node_instance.release_instance != NULL) { + node_instance.release_instance(&node_instance); + } } } diff --git a/src/apps/snmp/snmp_threadsync.c b/src/apps/snmp/snmp_threadsync.c index fdc1beb9..e016e362 100644 --- a/src/apps/snmp/snmp_threadsync.c +++ b/src/apps/snmp/snmp_threadsync.c @@ -194,13 +194,17 @@ do_sync(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* ins call_data->arg2.root_oid_len = root_oid_len; call_synced_function(call_data, fn); - instance->access = call_data->proxy_instance.access; - instance->asn1_type = call_data->proxy_instance.asn1_type; - instance->release_instance = threadsync_release_instance; - instance->get_value = (call_data->proxy_instance.get_value != NULL)? threadsync_get_value : NULL; - instance->set_value = (call_data->proxy_instance.set_value != NULL)? threadsync_set_value : NULL; - instance->set_test = (call_data->proxy_instance.set_test != NULL)? threadsync_set_test : NULL; - snmp_oid_assign(&instance->instance_oid, call_data->proxy_instance.instance_oid.id, call_data->proxy_instance.instance_oid.len); + if(call_data->retval.u8 == SNMP_ERR_NOERROR) { + instance->access = call_data->proxy_instance.access; + instance->asn1_type = call_data->proxy_instance.asn1_type; + instance->release_instance = threadsync_release_instance; + instance->get_value = (call_data->proxy_instance.get_value != NULL)? threadsync_get_value : NULL; + instance->set_value = (call_data->proxy_instance.set_value != NULL)? threadsync_set_value : NULL; + instance->set_test = (call_data->proxy_instance.set_test != NULL)? threadsync_set_test : NULL; + snmp_oid_assign(&instance->instance_oid, call_data->proxy_instance.instance_oid.id, call_data->proxy_instance.instance_oid.len); + } else { + mem_free(call_data); + } return call_data->retval.u8; } else {