Files
bun.sh/src
robobun 635034ee33 fix(shell): use-after-free in runFromJS when setupIOBeforeRun fails (#26920)
## Summary

- Fixes #26918 — segfault at address `0x28189480080` caused by
use-after-free in the shell interpreter
- When `setupIOBeforeRun()` fails (e.g., stdout handle unavailable on
Windows), the `runFromJS` error path called `deinitFromExec()` which
directly freed the GC-managed interpreter object with
`allocator.destroy(this)`. When the GC later swept and called
`deinitFromFinalizer()` on the already-freed memory, it caused a
segfault.
- Replaced `deinitFromExec()` with `derefRootShellAndIOIfNeeded(true)`
which properly cleans up runtime resources (IO handles, shell
environment) while leaving final object destruction to the GC finalizer
— matching the pattern already used in `finish()`.

## Test plan

- [x] Added regression test in `test/regression/issue/26918.test.ts`
that verifies the shell interpreter handles closed stdout gracefully
without crashing
- [x] Test passes with `bun bd test test/regression/issue/26918.test.ts`
- [ ] The actual crash is primarily reproducible on Windows where stdout
handles can be truly unavailable — CI Windows tests should validate the
fix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2026-02-11 17:51:10 -08:00
..
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2026-02-03 22:18:40 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-20 20:56:02 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-12-25 14:00:58 -08:00
2025-11-10 14:38:26 -08:00
2025-10-04 02:17:55 -07:00
2025-07-29 19:35:46 -07:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2026-01-07 12:33:21 -08:00
2025-11-10 14:38:26 -08:00
2025-11-20 20:56:02 -08:00
2025-07-21 13:26:47 -07:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-07-21 13:26:47 -07:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-09-09 20:41:10 -07:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2026-01-30 01:38:45 -08:00
2025-12-01 21:59:11 -08:00
2025-11-10 14:38:26 -08:00
2025-07-21 13:26:47 -07:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-07-21 13:26:47 -07:00
2025-07-21 13:26:47 -07:00