Skip to content

fix: preserve Win32 allocator alignment across free and resize - #3

Merged
dogukani merged 1 commit into
mainfrom
fix/win32-aligned-allocator
Sep 24, 2026
Merged

dogukani merged 1 commit into
mainfrom
fix/win32-aligned-allocator

Conversation

@dogukani

@dogukani dogukani commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

image-demo crashes on its first animation frame with Windows exit code 0xC0000374. The canvas store requests a 128-byte-aligned pixel buffer. Win32 Allocator::allocatePreferSpiram returned _aligned_malloc memory for that request, while Allocator::free passed the pointer to std::free. AddressSanitizer identifies this mismatched free in CanvasStore::bindDisplayFramebuffer.

Change

Store the underlying malloc block and requested alignment with each allocation. Return an aligned view, preserve that alignment and existing bytes when resizing, and free the underlying block through the matching allocator.

Verification

  • Before the patch, a fresh image-demo build exited on tick 1 with 0xC0000374; AddressSanitizer reported an invalid free at win32_memory.cpp:31.
  • With the patch, AddressSanitizer and release builds completed 100 frames and exited 0. The release capture shows the decoded animated Earth.
  • A native AddressSanitizer probe passed aligned allocate, resize, and free checks at 1, 8, 16, 128, and 4096 bytes, including data preservation, zero-size behavior, and allocation overflow.
  • notes-jsx built, exited 0 through GEA_WINDOWS_VERIFY_ONCE, and rendered its initial notes view.

Summary by CodeRabbit

  • Bug Fixes
    • Improved memory allocation and resizing reliability on Windows. Requests with invalid sizes or alignments are handled safely, and allocations respect the required alignment.
    • Resizing now preserves the existing allocation if a replacement cannot be created, and zero-size requests release the allocation and return no memory.

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 7c95bc22-8715-4b50-9427-ba8e09e843c9

📥 Commits

Reviewing files that changed from the base of the PR and between 397cd73 and 2a8157f.

📒 Files selected for processing (1)
  • packages/geastack-windows/targets/win32/main/win32_memory.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The Windows allocator now validates allocation sizes and alignments, stores metadata for aligned blocks, and uses that metadata to reallocate and free memory.

Changes

Windows allocator

Layer / File(s) Summary
Allocation and reallocation
packages/geastack-windows/targets/win32/main/win32_memory.cpp
Allocation validates size and alignment, checks for padding overflow, aligns the returned pointer, and records the allocation base, size, and effective alignment. Reallocation preserves alignment, copies the smaller block size, and frees the old block only after a successful allocation. free releases the recorded base pointer.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: dashersw

Merge Risk: ⚪ Minimal · up to 2a815

The Windows allocator now records each block's original address and alignment. Aligned allocations are freed and resized correctly, which fixes the reported heap-corruption crash in image-demo. No remaining defect was found in the Windows target code. Shared framework code built from external packages could not be inspected, so owners should confirm it never frees allocator memory with the C runtime directly.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving Win32 allocator alignment during deallocation and resizing.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@dogukani
dogukani merged commit d14e787 into main Sep 24, 2026
3 checks passed
@dogukani
dogukani deleted the fix/win32-aligned-allocator branch September 24, 2026 01:22
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant