From 0109e3c1f3a515ed716ddbdc261e0ed2e3f8e640 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 18 Aug 2008 10:48:21 +0200 Subject: [PATCH] snmp plugin: Fix a possible memory leak. The result was not freed when `csnmp_instance_list_add' failed. This rarely happens in 4.3, but later versions will be more strict in the function, so this became a problem. --- src/snmp.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/snmp.c b/src/snmp.c index 460624b4..408defa9 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -1120,10 +1120,6 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) vb = res->variables; if (vb == NULL) { - if (res != NULL) - snmp_free_pdu (res); - res = NULL; - status = -1; break; } @@ -1132,10 +1128,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) * subtree */ if (csnmp_check_res_left_subtree (host, data, res) != 0) { - if (res != NULL) - snmp_free_pdu (res); - res = NULL; - + status = 0; break; } @@ -1157,11 +1150,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) (vb != NULL) && (vb->next_variable != NULL); vb = vb->next_variable) /* do nothing */; - if (vb == NULL) - { - status = -1; - break; - } + assert (vb != NULL); /* Copy OID to oid_list[data->values_len] */ memcpy (oid_list[data->values_len].oid, vb->name, @@ -1224,6 +1213,10 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) res = NULL; } /* while (status == 0) */ + if (res != NULL) + snmp_free_pdu (res); + res = NULL; + if (status == 0) csnmp_dispatch_table (host, data, instance_list, value_table); -- 2.30.2