Skip to content

Fix crash when restarting mongoose server on Windows#7462

Open
Goober5000 wants to merge 1 commit into
scp-fs2open:masterfrom
Goober5000:fix/mongoose_crash
Open

Fix crash when restarting mongoose server on Windows#7462
Goober5000 wants to merge 1 commit into
scp-fs2open:masterfrom
Goober5000:fix/mongoose_crash

Conversation

@Goober5000
Copy link
Copy Markdown
Contributor

mg_start() calls InitializeCriticalSection(&global_log_file_lock) on every invocation, but mg_stop() never calls DeleteCriticalSection. Re-initializing an already-initialized critical section is undefined behavior on Windows and corrupts the heap, causing the next allocation to throw an exception.

Make the Win32 initialization (WSAStartup + InitializeCriticalSection) one-shot via a static flag, and remove the asymmetric WSACleanup from mg_stop so resources remain valid across mg_start/mg_stop cycles.

mg_start() calls InitializeCriticalSection(&global_log_file_lock) on
every invocation, but mg_stop() never calls DeleteCriticalSection.
Re-initializing an already-initialized critical section is undefined
behavior on Windows and corrupts the heap, causing the next allocation
to throw an exception.

Make the Win32 initialization (WSAStartup + InitializeCriticalSection)
one-shot via a static flag, and remove the asymmetric WSACleanup from
mg_stop so resources remain valid across mg_start/mg_stop cycles.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Goober5000 Goober5000 added the fix A fix for bugs, not-a-bugs, and/or regressions. label May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix A fix for bugs, not-a-bugs, and/or regressions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant