Commit 2e8a89e
Fix use-after-free in XMLHttpRequest::Send continuation
The completion continuation scheduled by Send captures `this` raw with no
lifetime guarantee. If the JS XMLHttpRequest wrapper is garbage-collected
while the request is in flight (e.g. once the requesting script drops its
reference), the wrapper -- and the C++ object behind it -- is destroyed
before the continuation runs on the runtime scheduler, so dereferencing
m_request / m_eventHandlerRefs / m_readyState faults (access violation).
Anchor the wrapper for the duration of the request with a strong
Napi::ObjectReference held in a shared_ptr captured by the continuation,
mirroring FileReader's existing anchor pattern. The anchor is released
automatically once the request settles and the lambda is destroyed, so
there is no member self-reference to clear and no extra teardown path.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 000f5c9 commit 2e8a89e
1 file changed
Lines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
262 | 274 | | |
263 | 275 | | |
264 | 276 | | |
265 | 277 | | |
266 | | - | |
| 278 | + | |
267 | 279 | | |
268 | 280 | | |
269 | 281 | | |
| |||
0 commit comments