Skip to content

Conversation

@forketyfork
Copy link
Owner

Summary

Fixes a memory leak in src/app/runtime.zig where sessions_storage would leak if the subsequent sessions allocation failed.

Problem

The allocation sequence was:

  1. Allocate sessions_storage
  2. Allocate sessions
  3. Install defer block to free both

If step 2 failed, the defer block would never be installed, leaving sessions_storage leaked.

Solution

Added errdefer allocator.free(sessions_storage); immediately after the first allocation. This ensures cleanup on any failure path before the defer is installed. Once the defer block is registered, it takes over responsibility for freeing both allocations on normal exit paths.

Issue: Memory leak when sessions allocation fails after sessions_storage
is allocated but before the defer block is installed.

Solution: Added errdefer to free sessions_storage immediately after its
allocation. If the subsequent sessions allocation fails, errdefer ensures
sessions_storage is freed. Once the defer block is installed, it takes
over responsibility for freeing both allocations on normal exit paths.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 096bfe3fcd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Scope the errdefer inside a labeled block so it only covers the gap
between the two allocations. Once the block exits, the defer block
takes sole ownership of freeing sessions_storage.
@forketyfork forketyfork merged commit ecb8a5d into main Jan 28, 2026
4 checks passed
@forketyfork forketyfork deleted the fix/sessions-storage-leak branch January 28, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants