Skip to content

Commit

Permalink
Merge pull request #2495 from bitshares/pr-2490-fix-es-crash
Browse files Browse the repository at this point in the history
Reset cURL options for different request type
  • Loading branch information
abitmore authored Aug 5, 2021
2 parents c2496e9 + d9fa5be commit 4020353
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion libraries/utilities/elasticsearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,23 @@ const std::string doCurl(CurlRequest& curl)
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");

// Note: the variable curl.handler has a long lifetime, it only gets initialized once, then be used many times,
// thus we need to clear old data
curl_easy_setopt(curl.handler, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl.handler, CURLOPT_URL, curl.url.c_str());
curl_easy_setopt(curl.handler, CURLOPT_CUSTOMREQUEST, curl.type.c_str());
curl_easy_setopt(curl.handler, CURLOPT_CUSTOMREQUEST, curl.type.c_str()); // this is OK
if(curl.type == "POST")
{
curl_easy_setopt(curl.handler, CURLOPT_HTTPGET, false);
curl_easy_setopt(curl.handler, CURLOPT_POST, true);
curl_easy_setopt(curl.handler, CURLOPT_POSTFIELDS, curl.query.c_str());
}
else // GET or DELETE (only these are used in this file)
{
curl_easy_setopt(curl.handler, CURLOPT_POSTFIELDS, NULL);
curl_easy_setopt(curl.handler, CURLOPT_POST, false);
curl_easy_setopt(curl.handler, CURLOPT_HTTPGET, true);
}
curl_easy_setopt(curl.handler, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl.handler, CURLOPT_WRITEDATA, (void *)&CurlReadBuffer);
curl_easy_setopt(curl.handler, CURLOPT_USERAGENT, "libcrp/0.1");
Expand Down

0 comments on commit 4020353

Please sign in to comment.