From ca734bb13497f02186c4c5046ce8f515ba4557ac Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 23 Nov 2014 14:03:44 +0100 Subject: [PATCH] patches: Added bts770688_snmp_memleak. Upstream fix for a memory leak in the SNMP plugin. Thanks to Marc Fournier for reporting this. Closes: #770688 --- debian/changelog | 3 ++ debian/patches/00list | 1 + debian/patches/bts770688_snmp_memleak.dpatch | 53 ++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100755 debian/patches/bts770688_snmp_memleak.dpatch diff --git a/debian/changelog b/debian/changelog index cb8bac3..1204589 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,6 +13,9 @@ collectd (5.4.1-6) UNRELEASED; urgency=medium - Added bts750440_config_segfault: upstream fix for a segfault when including empty config files; thanks to Bernd Zeimetz and Marc Fournier for reporting this (Closes: #750440, #770685). + - Added bts770688_snmp_memleak: upstream fix for a memory leak in the + SNMP plugin; thanks to Marc Fournier for reporting this + (Closes: #770688). -- Sebastian Harl Sun, 23 Nov 2014 13:04:03 +0100 diff --git a/debian/patches/00list b/debian/patches/00list index bb9acff..51d49a0 100644 --- a/debian/patches/00list +++ b/debian/patches/00list @@ -8,3 +8,4 @@ bts770681_riemann_ack.dpatch bts747093_lvm_segfault.dpatch bts770683_curl_init.dpatch bts750440_config_segfault.dpatch +bts770688_snmp_memleak.dpatch diff --git a/debian/patches/bts770688_snmp_memleak.dpatch b/debian/patches/bts770688_snmp_memleak.dpatch new file mode 100755 index 0000000..6cdaa1c --- /dev/null +++ b/debian/patches/bts770688_snmp_memleak.dpatch @@ -0,0 +1,53 @@ +#! /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); + -- 2.30.2