Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guarantee that curl_multi_remove_handle is called #423

Merged
merged 2 commits into from
Nov 13, 2021

Conversation

sagebind
Copy link
Collaborator

@sagebind sagebind commented Nov 11, 2021

Add a drop handler that guarantees that curl_multi_remove_handle is always called on easy handles added to a multi handle before the easy handle is dropped. Based on curl/curl#7982, we should not be allowing users to drop a previously attached handle without first calling curl_multi_remove_handle. In curl versions between 7.77 and 7.80 this could cause a crash under certain circumstances. While this will likely be fixed in the next curl version, it is still recommended to not allow this, plus we must still handle this case for users who may not have updated to a patched libcurl.

I'm not totally happy with how this is implemented as it adds an Arc::clone call every time an easy handle is added to a multi handle, but I couldn't think of a better way of guaranteeing this behavior without breaking API changes.

I've verified that this does actually fix #421 even without the upstream curl patch.

Fixes #421.

Add a drop handler that guarantees that `curl_multi_remove_handle` is always called on easy handles added to a multi handle before the easy handle is dropped. Based on curl/curl#7982, we should not be allowing users to drop a previously attached handle without first calling `curl_multi_remove_handle`. In curl versions between 7.77 and 7.80 this could cause a crash under certain circumstances. While this will likely be fixed in the next curl version, it is still recommended to not allow this, plus we must still handle this case for users who may not have updated to a patched libcurl.

I'm not totally happy with how this is implemented as it adds an `Arc::clone` call every time an easy handle is added to a multi handle, but I couldn't think of a better way of guaranteeing this behavior without breaking API changes.

Fixes #421.
@sagebind
Copy link
Collaborator Author

@iiibui Can you verify that using this branch fixes your crashes even with curl 7.80? It prevented the double-free errors in my tests.

@iiibui
Copy link

iiibui commented Nov 11, 2021

@iiibui Can you verify that using this branch fixes your crashes even with curl 7.80? It prevented the double-free errors in my tests.

This branch fixes my origin crashes with curl 7.80, but I found it has no effect with curl commit 51c0ebcff2140c38ff389b4fcfb8216f5e9d198c......

Copy link
Owner

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me! In the grand scheme of things Arc::clone isn't too bad compared to HTTP so I'm not too too worried about the perf here myself.

@sagebind
Copy link
Collaborator Author

@iiibui Hmm yeah, I still get the double-free against 51c0ebcff2140c38ff389b4fcfb8216f5e9d198c as well, which first appears in curl 7.77.0. Seems like after this PR though we're doing things exactly as curl recommends and any other issues are likely on curl. Here's the behavior I see:

So the only released version with this issue still is 7.77.0, but that version had a known issue around that which was fixed in 7.78.0: curl/curl#7236.

@sagebind sagebind merged commit 88b5171 into main Nov 13, 2021
@sagebind sagebind deleted the always-remove-easy-handles branch November 13, 2021 19:17
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.

curl::multi::Multi will make double free memory problem when some ssl error occurred
3 participants