Occasional use-after-free in multi_done() libcurl-7.81.0
In libcurl 7.81.0, multi_done() returns a connection to the cache and then dereferences it, which can cause a use-after-free if another thread reuses or frees the connection. An attacker could potentially trigger a crash or memory corruption, though the impact is uncertain.
Originally disclosed on HackerOne
- Disclosed after 40 days
We are seeing the use of a struct connectdata * on a thread after it was returned to the connection cache (and thus available for use on other threads including potential deallocation) in multi_done() in libcurl-7.81.0. This could occasionally result in an actual use-after-free, witnessed on Windows 10 platform.
Steps To Reproduce:
multi_done()line 717 a call is made toCurl_conncache_return_conn()Curl_conncache_return_conn()returnsTRUE(conn was returned to the cache and available for use in other threads) and execution continues on line 719 where the code derefs the now unownedconnto get theconnection_id- We have a fork with a commit that both tests (inline, not formally) and offers a potential fix for this issue.
- See attached screenshot showing assert firing in debug build
Impact
Unsure.
I'm not a hacker, and would have been happy to submit this as a GitHub issue instead, but discretion being the better part of valor, decided to post this issue here instead :)
Tangentially, I do not care to get credit or receive a bounty for this issue. Would be great to get this fixed as I suggested or in some other manner, thanks!
Attachments

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
What the attacker needed
Multi-threaded use of libcurl
How it was found
- multi_done() calls Curl_conncache_return_conn()
- Curl_conncache_return_conn() returns TRUE, meaning the connection is back in the cache
- Execution continues and dereferences the connection to get the connection_id
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A use-after-free happens when a program keeps using memory after it has been freed, which can lead to crashes or worse. Here, a function gives a connection back to a shared pool and then reads from it, so another thread might have already taken or freed it.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.