From: Florian Forster Date: Tue, 6 Nov 2007 15:53:49 +0000 (+0000) Subject: snmp plugin: (Hopefully) fix a memory leak. X-Git-Tag: collectd-4.1.4~3 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=83037eab40e9bba3803534d0b2b93c1c282dd564;p=collectd.git snmp plugin: (Hopefully) fix a memory leak. --- diff --git a/src/snmp.c b/src/snmp.c index 4bcdcf7d..f1b366b6 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -593,24 +593,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 */ @@ -848,6 +834,7 @@ 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) @@ -858,6 +845,11 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) ERROR ("snmp plugin: host %s: snmp_sess_synch_response failed: %s", host->name, (errstr == NULL) ? "Unknown problem" : errstr); csnmp_host_close_session (host); + sfree (errstr); + + if (res != NULL) + snmp_free_pdu (res); + res = NULL; status = -1; break; @@ -1081,6 +1073,8 @@ 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) @@ -1093,6 +1087,10 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data) csnmp_host_close_session (host); sfree (errstr); + if (res != NULL) + snmp_free_pdu (res); + res = NULL; + return (-1); }