From: Alexander A. Klimov Date: Fri, 15 Mar 2019 12:15:24 +0000 (+0100) Subject: ElasticsearchWriter: don't leak sockets X-Git-Tag: v2.11.0-rc1~200^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=refs%2Fpull%2F7020%2Fhead;p=icinga2 ElasticsearchWriter: don't leak sockets refs #7018 --- diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index 53ed48f97..e66a79076 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -8,6 +8,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" @@ -445,6 +446,8 @@ void ElasticsearchWriter::SendRequest(const String& body) if (!stream) return; + Defer close ([&stream]() { stream->Close(); }); + HttpRequest req(stream); /* Specify required headers by Elasticsearch. */