From 44b58e24130371449591a0090a50de4e7badf727 Mon Sep 17 00:00:00 2001 From: kp-cat <52385411+kp-cat@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:56:37 +0200 Subject: [PATCH] curl close fix --- .github/workflows/cpp-ci.yml | 5 +++-- src/curlnetworkadapter.cpp | 5 ++++- test/test-configcatclient.cpp | 12 +++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/cpp-ci.yml b/.github/workflows/cpp-ci.yml index f3da7a4..f7b3548 100644 --- a/.github/workflows/cpp-ci.yml +++ b/.github/workflows/cpp-ci.yml @@ -16,7 +16,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ windows-latest, macos-latest, ubuntu-latest ] + os: [ windows-latest ] env: CTEST_OUTPUT_ON_FAILURE: 1 @@ -49,7 +49,8 @@ jobs: - name: Test working-directory: build - run: ctest -j4 + run: | + C:\"Program Files (x86)\Windows Kits"\10\Debuggers\x64\cdb -c ".lines -e;g;q" -G google_tests coverage: needs: [ test ] diff --git a/src/curlnetworkadapter.cpp b/src/curlnetworkadapter.cpp index 69e7409..cc767a3 100644 --- a/src/curlnetworkadapter.cpp +++ b/src/curlnetworkadapter.cpp @@ -41,7 +41,9 @@ std::shared_ptr LibCurlResourceGuard::instance = nullptr; std::mutex LibCurlResourceGuard::mutex; int ProgressCallback(void* clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { - return static_cast(clientp)->ProgressFunction(dltotal, dlnow, ultotal, ulnow); + if (clientp) + return static_cast(clientp)->ProgressFunction(dltotal, dlnow, ultotal, ulnow); + return 1; // Return abort } int CurlNetworkAdapter::ProgressFunction(curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { @@ -157,6 +159,7 @@ void CurlNetworkAdapter::close() { CurlNetworkAdapter::~CurlNetworkAdapter() { if (curl) { + curl_easy_setopt(curl, CURLOPT_XFERINFODATA, NULL); curl_easy_cleanup(curl); } } diff --git a/test/test-configcatclient.cpp b/test/test-configcatclient.cpp index efd231f..91d0b05 100644 --- a/test/test-configcatclient.cpp +++ b/test/test-configcatclient.cpp @@ -38,23 +38,21 @@ TEST_F(ConfigCatClientTest, EnsureSingletonPerSdkKey) { } TEST_F(ConfigCatClientTest, EnsureCloseWorks) { - ConfigCatOptions options; - options.pollingMode = PollingMode::manualPoll(); - auto client = ConfigCatClient::get("another-90123456789012/1234567890123456789012", &options); - auto client2 = ConfigCatClient::get("another-90123456789012/1234567890123456789012", &options); + auto client = ConfigCatClient::get("another-90123456789012/1234567890123456789012"); + auto client2 = ConfigCatClient::get("another-90123456789012/1234567890123456789012"); EXPECT_TRUE(client2 == client); EXPECT_TRUE(ConfigCatClient::instanceCount() == 1); ConfigCatClient::close(client2); EXPECT_TRUE(ConfigCatClient::instanceCount() == 0); - client = ConfigCatClient::get("another-90123456789012/1234567890123456789012", &options); + client = ConfigCatClient::get("another-90123456789012/1234567890123456789012"); EXPECT_TRUE(ConfigCatClient::instanceCount() == 1); ConfigCatClient::closeAll(); EXPECT_TRUE(ConfigCatClient::instanceCount() == 0); - client = ConfigCatClient::get("another-90123456789012/1234567890123456789012", &options); + client = ConfigCatClient::get("another-90123456789012/1234567890123456789012"); EXPECT_TRUE(ConfigCatClient::instanceCount() == 1); } @@ -89,7 +87,7 @@ TEST_P(SdkKeyFormatValidationTestSuite, SdkKeyFormatValidation) { if (!isValid) { FAIL() << "Expected invalid_argument exception"; } - } catch (const invalid_argument& e) { + } catch (const invalid_argument&) { if (isValid) { FAIL() << "Did not expect invalid_argument exception"; }