Skip to content

prevent leaking of CURL handles#36

Merged
dgoffredo merged 1 commit intomainfrom
david.goffredo/curl-handle-leak
May 31, 2023
Merged

prevent leaking of CURL handles#36
dgoffredo merged 1 commit intomainfrom
david.goffredo/curl-handle-leak

Conversation

@dgoffredo
Copy link
Copy Markdown
Contributor

See #31.

In addition to the recommended change, this revision also adds unit tests that verify that a CURL handle, once created, is destroyed.

@dgoffredo dgoffredo requested a review from cgilmour May 18, 2023 22:21
Comment thread test/test_curl.cpp
user_data_on_write_ = data;
return CURLE_OK;
}
class SingleRequestMockCurlLibrary : public CurlLibrary {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is moved and renamed from the class MockCurlLibrary that used to be in the TEST_CASE("parse response headers and body"). It's used there and in the new test case.

I also added data members created_handles_, destroyed_handles_, message_result_, and delay_message_.

@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented May 18, 2023

Benchmarks

Comparing candidate commit 2c261a4 in PR branch david.goffredo/curl-handle-leak with baseline commit 338a87e in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics.

Comment thread test/test_curl.cpp
Comment on lines +431 to +433
// Here are the checks relevant to this test.
REQUIRE(library.created_handles_.size() == 1);
REQUIRE(library.created_handles_ == library.destroyed_handles_);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SECTIONs above are all setup. The post-condition, here, is always the same: one handle created and one handle destroyed.

@dgoffredo
Copy link
Copy Markdown
Contributor Author

I find that "hide whitespace" in the diff gearbox menu improves the diff.

Copy link
Copy Markdown
Contributor

@cgilmour cgilmour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems OK, marking as approved.
Are there any consequences to doing this with a request in-flight?

@dgoffredo
Copy link
Copy Markdown
Contributor Author

Thanks!

Are there any consequences to doing this with a request in-flight?

Nope, removing the easy handle from the multi-handle (event loop) unregisters it from anything that would drive its installed callbacks. Then cleaning up the easy handle frees resources.

@dgoffredo dgoffredo merged commit ec35054 into main May 31, 2023
@dgoffredo dgoffredo deleted the david.goffredo/curl-handle-leak branch May 31, 2023 13:28
cataphract pushed a commit to cataphract/dd-trace-cpp that referenced this pull request Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants