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

hyper: fix ownership problems #11745

Closed
wants to merge 1 commit into from

Conversation

nnethercote
Copy link
Contributor

Some of these changes come from comparing Curl_http and start_CONNECT, which are similar, and adding things to them that are present in one and missing in another.

The most important changes:

  • In start_CONNECT, add a missing hyper_clientconn_free call on the happy path.
  • In start_CONNECT, add a missing hyper_request_free on the error path.
  • In bodysend, add a missing hyper_body_free on an early-exit path.
  • In bodysend, remove an unnecessary hyper_body_free on a different error path that would cause a double-free. https://docs.rs/hyper/latest/hyper/ffi/fn.hyper_request_set_body.html says of hyper_request_set_body: "This takes ownership of the hyper_body *, you must not use it or free it after setting it on the request." This is true even if hyper_request_set_body returns an error; I confirmed this by looking at the hyper source code.

Other changes are minor but make things slightly nicer.

Some of these changes come from comparing `Curl_http` and
`start_CONNECT`, which are similar, and adding things to them that are
present in one and missing in another.

The most important changes:
- In `start_CONNECT`, add a missing `hyper_clientconn_free` call on the
  happy path.
- In `start_CONNECT`, add a missing `hyper_request_free` on the error
  path.
- In `bodysend`, add a missing `hyper_body_free` on an early-exit path.
- In `bodysend`, remove an unnecessary `hyper_body_free` on a different
  error path that would cause a double-free.
  https://docs.rs/hyper/latest/hyper/ffi/fn.hyper_request_set_body.html
  says of `hyper_request_set_body`: "This takes ownership of the
  hyper_body *, you must not use it or free it after setting it on the
  request." This is true even if `hyper_request_set_body` returns an
  error; I confirmed this by looking at the hyper source code.

Other changes are minor but make things slightly nicer.
@nnethercote
Copy link
Contributor Author

nnethercote commented Aug 28, 2023

I found these after looking very closely at ownership responsibilities in the hyper C API in hyperium/hyper#3296.

@bagder bagder closed this in 9b84f27 Aug 28, 2023
@bagder
Copy link
Member

bagder commented Aug 28, 2023

Thanks!

ptitSeb pushed a commit to wasix-org/curl that referenced this pull request Sep 25, 2023
Some of these changes come from comparing `Curl_http` and
`start_CONNECT`, which are similar, and adding things to them that are
present in one and missing in another.

The most important changes:
- In `start_CONNECT`, add a missing `hyper_clientconn_free` call on the
  happy path.
- In `start_CONNECT`, add a missing `hyper_request_free` on the error
  path.
- In `bodysend`, add a missing `hyper_body_free` on an early-exit path.
- In `bodysend`, remove an unnecessary `hyper_body_free` on a different
  error path that would cause a double-free.
  https://docs.rs/hyper/latest/hyper/ffi/fn.hyper_request_set_body.html
  says of `hyper_request_set_body`: "This takes ownership of the
  hyper_body *, you must not use it or free it after setting it on the
  request." This is true even if `hyper_request_set_body` returns an
  error; I confirmed this by looking at the hyper source code.

Other changes are minor but make things slightly nicer.

Closes curl#11745
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants