#! /bin/sh /usr/share/dpatch/dpatch-run ## bts770688_snmp_memleak.dpatch by Pierre-Yves Ritschard ## and Marc Fournier ## ## DP: Let snmp_synch_response deal with PDU freeing ## DP: ## DP: When reading from tables, upon errors the PDUs sent are already ## DP: freed by snmp_synch_response since they are right after ## DP: snmp_send is called. ## DP: ## DP: This commit syncs collectd's approach with other occurences of ## DP: snmp_synch_response calls. ## DP: ## DP: There might be a few corner cases where we leak PDUs, but it ## DP: is unclear how to check for those since we would need to ## DP: have an indication that snmp_send was never called, which ## DP: as far as I can tell is not possible. ## DP: ## DP: The potential for failure in snmp_send is rather low and will ## DP: be easily spotted though, since when crafting invalid PDUs ## DP: snmp send will constantly fail and since valid configurations ## DP: can never leak memory. ## DP: ## DP: Upstream bug reports: ## DP: https://github.com/collectd/collectd/issues/610 ## DP: https://github.com/collectd/collectd/issues/804 @DPATCH@ diff --git a/src/snmp.c b/src/snmp.c index ad81c89..7d340d1 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -1316,6 +1316,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); @@ -1437,6 +1439,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);