From: Alexander A. Klimov Date: Fri, 15 Mar 2019 12:15:24 +0000 (+0100) Subject: ElasticsearchWriter: don't leak sockets X-Git-Tag: v2.10.4~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29e8961cda0ac8279189fc4d2379ba0033d57895;p=icinga2 ElasticsearchWriter: don't leak sockets refs #7018 (cherry picked from commit b2e2b587da530a5b79f746ed0db5b3804b502e07) --- diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index 029857094..2287365ef 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -25,6 +25,7 @@ #include "icinga/compatutility.hpp" #include "icinga/service.hpp" #include "icinga/checkcommand.hpp" +#include "base/defer.hpp" #include "base/tcpsocket.hpp" #include "base/stream.hpp" #include "base/base64.hpp" @@ -441,6 +442,8 @@ void ElasticsearchWriter::SendRequest(const String& body) if (!stream) return; + Defer close ([&stream]() { stream->Close(); }); + HttpRequest req(stream); /* Specify required headers by Elasticsearch. */