diff --git a/core/src/CurlHttpClient.cc b/core/src/CurlHttpClient.cc index 75fc05560..847857dec 100644 --- a/core/src/CurlHttpClient.cc +++ b/core/src/CurlHttpClient.cc @@ -221,6 +221,7 @@ CurlHttpClient::makeRequest(const HttpRequest &request) { HttpMethodToString(request.method()) + " " + request.url().toString())); } } + curl_slist_free_all(list); } } // namespace AlibabaCloud diff --git a/core/src/EndpointProvider.cc b/core/src/EndpointProvider.cc index 99bc9df2f..16aca7a6b 100644 --- a/core/src/EndpointProvider.cc +++ b/core/src/EndpointProvider.cc @@ -19,6 +19,9 @@ #include #include #include +#include +#include +#include #ifndef WIN32 #include "LocalEndpoints.h" @@ -39,7 +42,10 @@ namespace #include #endif +std::mutex mutex; +std::condition_variable cv; bool local_endpoints_loaded = false; +bool local_endpoints_loading = false; typedef std::string productType; typedef std::string regionType; typedef std::string endpointType; @@ -60,6 +66,8 @@ static void LoadLocalEndpoints() { Json::Reader reader; Json::Value value; + std::unique_lock lock(mutex); + if (local_endpoints_loaded) { return; @@ -76,6 +84,10 @@ static void LoadLocalEndpoints() return; } + cv.wait(lock, [] { return !local_endpoints_loading; });// continue if loading completed + + local_endpoints_loading = true; + auto regions = value["regions"]; for (const auto ®ion : regions) { @@ -107,6 +119,10 @@ static void LoadLocalEndpoints() allLocalEndpoints[product] = p; } local_endpoints_loaded = true; + local_endpoints_loading = false; + + lock.unlock(); + cv.notify_one(); } } // namespace diff --git a/core/src/HttpMessage.cc b/core/src/HttpMessage.cc index ee81c62d4..80bbad57f 100644 --- a/core/src/HttpMessage.cc +++ b/core/src/HttpMessage.cc @@ -139,7 +139,7 @@ HttpMessage::HeaderValueType HttpMessage::header(KnownHeader header)const { void HttpMessage::setBody(const char *data, size_t size) { if (body_) - delete body_; + delete[] body_; body_ = nullptr; bodySize_ = 0; if (size) {