Skip to content

hyper: fix ownership problems#11745

Closed
nnethercote wants to merge 1 commit intocurl:masterfrom
nnethercote:hyper-ownership-fixes
Closed

hyper: fix ownership problems#11745
nnethercote wants to merge 1 commit intocurl:masterfrom
nnethercote:hyper-ownership-fixes

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.

2 participants