ASAN: heap-use-after-free in parse_url (line 717)
Bug Report: heap-use-after-free in httplib::detail::parse_url
ASAN Output
AddressSanitizer: heap-use-after-free on address 0x51600004a2e8
SUMMARY: AddressSanitizer: heap-use-after-free httplib.h:717:18 in httplib::detail::parse_url(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, httplib::detail::UrlComponents&)
Details
- Commit:
b1cc8095a8feca1b99e296ef78eddd312e80d2c6(short:b1cc809) - File:
httplib.h, line 717 - Function:
httplib::detail::parse_url - Detection method: AddressSanitizer during CI release-gates testing
Context
This bug was detected during CI testing of the cxxmcp project, which uses httplib as a third-party dependency for HTTP transport. The heap-use-after-free occurs in parse_url, suggesting a lifetime issue with string or buffer references during URL parsing.
Closing this issue — the root cause is in cxxmcp's lifetime management, not httplib.
ASAN analysis shows:
HttpTransport::Implis freed on thread T0 via~Client()→~HttpTransport()→~Impl()- An executor worker thread (T21) is still running
send()→make_client()→parse_url(), accessing the already-freedImplmemberorigin(astd::string)
The call chain:
freed: ~Client() → ~HttpTransport() → ~Impl() (operator delete)
used: Executor::worker_loop() → call_tool_async → send() → make_client() → parse_url(impl->origin) ← use-after-free
The Client is destroyed while an async request spawned by call_tool_async is still in-flight. The fix needs to ensure the transport outlives all in-flight async operations (e.g., drain the executor or join worker threads before destroying the transport).
Apologies for the false alarm — httplib is working correctly here.