fix : code patch

1. fixed code about delete char*
2. free curl_slist
3. added lock for EndpointProvider::LoadLocalEndpoints()
This commit is contained in:
wb-hx510875
2020-04-28 15:51:36 +08:00
committed by Axios
parent a51834c8d0
commit f16150baca
3 changed files with 18 additions and 1 deletions

View File

@@ -221,6 +221,7 @@ CurlHttpClient::makeRequest(const HttpRequest &request) {
HttpMethodToString(request.method()) + " " + request.url().toString()));
}
}
curl_slist_free_all(list);
}
} // namespace AlibabaCloud

View File

@@ -19,6 +19,9 @@
#include <iomanip>
#include <json/json.h>
#include <sstream>
#include <thread>
#include <mutex>
#include <condition_variable>
#ifndef WIN32
#include "LocalEndpoints.h"
@@ -39,7 +42,10 @@ namespace
#include <strings.h>
#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<std::mutex> 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 &region : 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

View File

@@ -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) {