Skip to content

Commit

Permalink
Merge pull request #6990 from Icinga/bugfix/influxdbwriter-oom-6989
Browse files Browse the repository at this point in the history
InfluxdbWriter: don't leak sockets
  • Loading branch information
Michael Friedrich authored Mar 18, 2019
2 parents 66246bd + 2a6b122 commit 2de8bac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/base/defer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class Defer
inline
~Defer()
{
m_Func();
try {
m_Func();
} catch (...) {
// https://stackoverflow.com/questions/130117/throwing-exceptions-out-of-a-destructor
}
}

private:
Expand Down
3 changes: 3 additions & 0 deletions lib/perfdata/influxdbwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 2de8bac

Please sign in to comment.