Skip to content

Free the curl handle when setup fails for InputStream responses in the native curl backend - #3092

Merged
adamw merged 2 commits into
masterfrom
fix-curl-handle-leak-on-send
Dec 3, 2026
Merged

adamw merged 2 commits into
masterfrom
fix-curl-handle-leak-on-send

Conversation

@adamw

@adamw adamw commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

In the Scala Native curl backend, requests with an InputStream response leaked the curl handle and the response buffers when request setup failed. This happened when the request body couldn't be read (e.g. a missing file, an InputStream body that throws, or a stream body, which curl doesn't support), or when curl_multi_add_handle failed.

handleBaseWithMulti now frees the handles and buffers on these failures and returns the error. The other paths already freed them.

No test: the leak is native memory only, and a test can't see it without test-only hooks in production code.

If request setup threw before a handler took over the curl handle, the
handle and the response buffers were never freed. Setup failures in send,
handleBase, handleFile and handleBaseWithMulti now free them.
@adamw
adamw force-pushed the fix-curl-handle-leak-on-send branch from a43f400 to 418fead Compare December 3, 2026 09:59
Setup in send can't throw, and handleBase and handleFile already free the
handle through ensure. Only handleBaseWithMulti leaked: when the request
body or curl_multi_add_handle failed, nothing freed the handles and buffers.
@adamw adamw changed the title Free the curl handle when request setup fails in the native curl backend Free the curl handle when setup fails for InputStream responses in the native curl backend Dec 3, 2026
@adamw
adamw merged commit e8e9022 into master Dec 3, 2026
68 of 71 checks passed
@adamw
adamw deleted the fix-curl-handle-leak-on-send branch December 3, 2026 13:44
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.

1 participant