Commit 79554e8
committed
fix: don't destroy server in stop() - causes use-after-free
The stop() method was calling m_server.reset() which destroys the
httplib::Server. But listen() is a blocking call that may still be on
the call stack in another thread. Destroying the server while listen()
is returning causes null pointer dereference (SIGSEGV at 0x20).
The crash was in httplib's process_request during map operations
(__construct_node at string:1793), where httplib was trying to copy
headers but the Server object had been destroyed.
Fix:
- stop() now only signals shutdown via m_server->stop(), does NOT
call reset() or clear()
- Destructor handles actual destruction: stops server, resets
(joins threads), then clears content
- This ensures the server is only destroyed after listen() has
fully returned and all threads are joined1 parent e9cf580 commit 79554e8
1 file changed
Lines changed: 13 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
94 | 99 | | |
95 | 100 | | |
96 | 101 | | |
| |||
239 | 244 | | |
240 | 245 | | |
241 | 246 | | |
242 | | - | |
243 | 247 | | |
244 | 248 | | |
245 | 249 | | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
251 | 256 | | |
252 | | - | |
253 | 257 | | |
254 | 258 | | |
255 | | - | |
256 | | - | |
| 259 | + | |
| 260 | + | |
257 | 261 | | |
258 | 262 | | |
259 | 263 | | |
| |||
0 commit comments