From 0fe3a254680c032184edd259ccc7f12e06ba065f Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 21 Dec 2022 14:50:31 +0100 Subject: [PATCH] MiniCurl: Make it safe to reuse a MiniCurl object --- pdns/minicurl.cc | 9 +++++++++ pdns/minicurl.hh | 1 + 2 files changed, 10 insertions(+) diff --git a/pdns/minicurl.cc b/pdns/minicurl.cc index 65b7f71b36a9..2a39e6aca857 100644 --- a/pdns/minicurl.cc +++ b/pdns/minicurl.cc @@ -118,6 +118,15 @@ static string extractHostFromURL(const std::string& url) void MiniCurl::setupURL(const std::string& str, const ComboAddress* rem, const ComboAddress* src, int timeout, size_t byteslimit, bool fastopen, bool verify) { + if (!d_fresh) { + curl_easy_reset(getCURLPtr(d_curl)); + } + else { + d_fresh = false; + } + + clearHostsList(); + if (rem) { struct curl_slist *hostlist = nullptr; // THIS SHOULD BE FREED diff --git a/pdns/minicurl.hh b/pdns/minicurl.hh index 28e426a8104a..08c88a6d75a2 100644 --- a/pdns/minicurl.hh +++ b/pdns/minicurl.hh @@ -69,6 +69,7 @@ private: #endif std::string d_data; size_t d_byteslimit{}; + bool d_fresh{true}; void setupURL(const std::string& str, const ComboAddress* rem, const ComboAddress* src, int timeout, size_t byteslimit, bool fastopen, bool verify); void setHeaders(const MiniCurlHeaders& headers);