Merge pull request #6990 from Icinga/bugfix/influxdbwriter-oom-6989

InfluxdbWriter: don't leak sockets
This commit is contained in:
Michael Friedrich 2019-03-18 14:38:04 +01:00 committed by GitHub
commit 2de8bac588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -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:

View File

@ -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());