fix: clean up semaphore if thread spawn fails

When std.Thread.spawn fails in the install() function, the semaphore
that was already initialized needs to be cleaned up to prevent a
resource leak. The C++ Bun::Semaphore object allocated by init()
would otherwise never be destroyed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2026-01-14 22:36:56 +00:00
parent 88b19a848a
commit a461b72ae7

View File

@@ -160,6 +160,8 @@ const posix = if (Environment.isPosix) struct {
.stack_size = 512 * 1024,
}, signalInspectorThread, .{}) catch |err| {
log("thread spawn failed: {s}", .{@errorName(err)});
if (semaphore) |sem| sem.deinit();
semaphore = null;
return false;
};