X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsnmp.c;h=4311ff1670b5f92a6e2927d16420e2c1c5f8a011;hb=24db3832cf2d74fe5425de379d10dc73d141c2f9;hp=8673df199e9ffe135993986a24f5cc1e1607b50e;hpb=8dfe4231f01b23205be2128a6f5c1e49a701ee83;p=collectd.git diff --git a/src/snmp.c b/src/snmp.c index 8673df19..4311ff16 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -656,24 +656,10 @@ static int csnmp_config (oconfig_item_t *ci) static void csnmp_host_close_session (host_definition_t *host) { - int status; - if (host->sess_handle == NULL) return; - status = snmp_sess_close (host->sess_handle); - - if (status != 0) - { - char *errstr = NULL; - - snmp_sess_error (host->sess_handle, NULL, NULL, &errstr); - - ERROR ("snmp plugin: host %s: snmp_sess_close failed: %s", - host->name, (errstr == NULL) ? "Unknown problem" : errstr); - sfree (errstr); - } - + snmp_sess_close (host->sess_handle); host->sess_handle = NULL; } /* void csnmp_host_close_session */ @@ -1107,15 +1093,22 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) for (i = 0; i < oid_list_len; i++) snmp_add_null_var (req, oid_list[i].oid, oid_list[i].oid_len); + res = NULL; status = snmp_sess_synch_response (host->sess_handle, req, &res); - if (status != STAT_SUCCESS) + if ((status != STAT_SUCCESS) || (res == NULL)) { char *errstr = NULL; snmp_sess_error (host->sess_handle, NULL, NULL, &errstr); ERROR ("snmp plugin: host %s: snmp_sess_synch_response failed: %s", host->name, (errstr == NULL) ? "Unknown problem" : errstr); + + if (res != NULL) + snmp_free_pdu (res); + res = NULL; + + sfree (errstr); csnmp_host_close_session (host); status = -1; @@ -1127,6 +1120,10 @@ 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; } @@ -1134,7 +1131,13 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) /* Check if all values (and possibly the instance) have left their * subtree */ if (csnmp_check_res_left_subtree (host, data, res) != 0) + { + if (res != NULL) + snmp_free_pdu (res); + res = NULL; + break; + } /* if an instance-OID is configured.. */ if (data->instance.oid.oid_len > 0) @@ -1314,17 +1317,24 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data) for (i = 0; i < data->values_len; i++) snmp_add_null_var (req, data->values[i].oid, data->values[i].oid_len); + + res = NULL; status = snmp_sess_synch_response (host->sess_handle, req, &res); - if (status != STAT_SUCCESS) + if ((status != STAT_SUCCESS) || (res == NULL)) { char *errstr = NULL; snmp_sess_error (host->sess_handle, NULL, NULL, &errstr); ERROR ("snmp plugin: host %s: snmp_sess_synch_response failed: %s", host->name, (errstr == NULL) ? "Unknown problem" : errstr); - csnmp_host_close_session (host); + + if (res != NULL) + snmp_free_pdu (res); + res = NULL; + sfree (errstr); + csnmp_host_close_session (host); return (-1); } @@ -1347,7 +1357,9 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data) data->scale, data->shift); } /* for (res->variables) */ - snmp_free_pdu (res); + if (res != NULL) + snmp_free_pdu (res); + res = NULL; DEBUG ("snmp plugin: -> plugin_dispatch_values (%s, &vl);", data->type); plugin_dispatch_values (data->type, &vl);