Skip to content

Commit 3280aca

Browse files
committed
fix possible NSInvalidArgumentException
1 parent acc923e commit 3280aca

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

lib/CurlWrapper.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,11 @@
2121
#include <assert.h>
2222
#include <curl/curl.h>
2323

24+
#include <mutex>
2425
#include <string>
2526

2627
namespace pulsar {
2728

28-
struct CurlInitializer {
29-
CurlInitializer() { curl_global_init(CURL_GLOBAL_ALL); }
30-
~CurlInitializer() { curl_global_cleanup(); }
31-
};
32-
static CurlInitializer curlInitializer;
33-
3429
class CurlWrapper {
3530
public:
3631
CurlWrapper() noexcept {}
@@ -47,6 +42,8 @@ class CurlWrapper {
4742

4843
// It must be called before calling other methods
4944
bool init() {
45+
static std::once_flag initFlag;
46+
std::call_once(initFlag, [] { curl_global_init(CURL_GLOBAL_ALL); });
5047
handle_ = curl_easy_init();
5148
return handle_ != nullptr;
5249
}

0 commit comments

Comments
 (0)