From a9841a9197e79461a3ed3a0efc79fca7d78f1a22 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 1 Mar 2019 14:29:35 +0100 Subject: [PATCH 1/2] Defer: ensure not to throw any exceptions out of a destructor refs #6989 --- lib/base/defer.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/base/defer.hpp b/lib/base/defer.hpp index 33cc197db..9290c92b9 100644 --- a/lib/base/defer.hpp +++ b/lib/base/defer.hpp @@ -30,7 +30,11 @@ public: inline ~Defer() { - m_Func(); + try { + m_Func(); + } catch (...) { + // https://stackoverflow.com/questions/130117/throwing-exceptions-out-of-a-destructor + } } private: From 2a6b122413dfc8762a7839bbe41c125455a17b5c Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 1 Mar 2019 14:30:49 +0100 Subject: [PATCH 2/2] InfluxdbWriter: don't leak sockets refs #6989 --- lib/perfdata/influxdbwriter.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index 773f21a2a..b75cd7a3f 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -9,6 +9,7 @@ #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" #include "icinga/checkcommand.hpp" +#include "base/defer.hpp" #include "base/tcpsocket.hpp" #include "base/configtype.hpp" #include "base/objectlock.hpp" @@ -447,6 +448,8 @@ void InfluxdbWriter::Flush() if (!stream) return; + Defer close ([&stream]() { stream->Close(); }); + Url::Ptr url = new Url(); url->SetScheme(GetSslEnable() ? "https" : "http"); url->SetHost(GetHost());