X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsnmp.c;h=cb0b70fa15275360feab4ac8df55b8b479c03f74;hb=dab48f284f9d4bb6ae98244310c5cdb6c5d91bf3;hp=3be2ae262b617bc1408ed74b9f72558295bed6c5;hpb=633c3966f770e4d46651a2fe219a18d8a9907a9f;p=collectd.git diff --git a/src/snmp.c b/src/snmp.c index 3be2ae26..cb0b70fa 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -359,7 +359,7 @@ static int csnmp_config_add_data_blacklist(data_definition_t *dd, oconfig_item_t { ERROR("snmp plugin: Can't allocate memory"); strarray_free(dd->ignores, dd->ignores_len); - return (ENOMEM); + return (ENOMEM); } } return 0; @@ -402,7 +402,6 @@ static int csnmp_config_add_data (oconfig_item_t *ci) for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; - status = 0; if (strcasecmp ("Type", option->key) == 0) status = cf_util_get_string(option, &dd->type); @@ -993,7 +992,8 @@ static value_t csnmp_value_list_to_value (struct variable_list *vl, int type, status = parse_value (string, &ret, type); if (status != 0) { - ERROR ("snmp plugin: csnmp_value_list_to_value: Parsing string as %s failed: %s", + ERROR ("snmp plugin: host %s: csnmp_value_list_to_value: Parsing string as %s failed: %s", + (host_name != NULL) ? host_name : "UNKNOWN", DS_TYPE_TO_STRING (type), string); } } @@ -1235,16 +1235,17 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat return (-1); } assert (ds->ds_num == data->values_len); + assert (data->values_len > 0); instance_list_ptr = instance_list; - value_table_ptr = malloc (sizeof (*value_table_ptr) * data->values_len); + value_table_ptr = calloc ((size_t) data->values_len, sizeof (*value_table_ptr)); if (value_table_ptr == NULL) return (-1); for (i = 0; i < data->values_len; i++) value_table_ptr[i] = value_table[i]; - vl.values_len = ds->ds_num; + vl.values_len = data->values_len; vl.values = malloc (sizeof (*vl.values) * vl.values_len); if (vl.values == NULL) { @@ -1423,6 +1424,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) data->type, ds->ds_num, data->values_len); return (-1); } + assert (data->values_len > 0); /* We need a copy of all the OIDs, because GETNEXT will destroy them. */ memcpy (oid_list, data->values, data->values_len * sizeof (oid_t)); @@ -1497,6 +1499,8 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) snmp_free_pdu (res); res = NULL; + /* snmp_synch_response already freed our PDU */ + req = NULL; sfree (errstr); csnmp_host_close_session (host); @@ -1520,7 +1524,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) for (vb = res->variables, i = 0; (vb != NULL); vb = vb->next_variable, i++) { /* Calculate value index from todo list */ - while (!oid_list_todo[i] && (i < oid_list_len)) + while ((i < oid_list_len) && !oid_list_todo[i]) i++; /* An instance is configured and the res variable we process is the @@ -1544,7 +1548,8 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) if (csnmp_instance_list_add (&instance_list_head, &instance_list_tail, res, host, data) != 0) { - ERROR ("snmp plugin: csnmp_instance_list_add failed."); + ERROR ("snmp plugin: host %s: csnmp_instance_list_add failed.", + host->name); status = -1; break; } @@ -1618,6 +1623,10 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) snmp_free_pdu (res); res = NULL; + if (req != NULL) + snmp_free_pdu (req); + req = NULL; + if (status == 0) csnmp_dispatch_table (host, data, instance_list_head, value_list_head); @@ -1662,7 +1671,7 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data) if (host->sess_handle == NULL) { - DEBUG ("snmp plugin: csnmp_read_table: host->sess_handle == NULL"); + DEBUG ("snmp plugin: csnmp_read_value: host->sess_handle == NULL"); return (-1); }