From: Florian Forster Date: Mon, 18 Aug 2008 08:48:21 +0000 (+0200) Subject: snmp plugin: Fix a possible memory leak. X-Git-Tag: collectd-4.3.4~18 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=0109e3c1f3a515ed716ddbdc261e0ed2e3f8e640;p=collectd.git 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. --- 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);