Skip to content

Commit

Permalink
curl close fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-cat committed Apr 2, 2024
1 parent 681a9a0 commit 44b58e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/cpp-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 ]
Expand Down
5 changes: 4 additions & 1 deletion src/curlnetworkadapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ std::shared_ptr<LibCurlResourceGuard> 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<CurlNetworkAdapter*>(clientp)->ProgressFunction(dltotal, dlnow, ultotal, ulnow);
if (clientp)
return static_cast<CurlNetworkAdapter*>(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) {
Expand Down Expand Up @@ -157,6 +159,7 @@ void CurlNetworkAdapter::close() {

CurlNetworkAdapter::~CurlNetworkAdapter() {
if (curl) {
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, NULL);
curl_easy_cleanup(curl);
}
}
Expand Down
12 changes: 5 additions & 7 deletions test/test-configcatclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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";
}
Expand Down

0 comments on commit 44b58e2

Please sign in to comment.