Skip to content

fix(heap): add CRITICAL_SECTION to protect tracking linked lists#6

Merged
TorinKS merged 1 commit intomainfrom
change/fix-heap-list-thread-safety
Mar 22, 2026
Merged

fix(heap): add CRITICAL_SECTION to protect tracking linked lists#6
TorinKS merged 1 commit intomainfrom
change/fix-heap-list-thread-safety

Conversation

@TorinKS
Copy link
Copy Markdown
Owner

@TorinKS TorinKS commented Mar 22, 2026

Add TrackingLock to GLOBAL_STATE, initialized in GetGlobalState() and cleaned up in CleanupHeap(). All linked list operations (insert, remove, traverse) on MemoryAllocations and FreedMemoryList are now protected. HeapAlloc/HeapFree for user memory stay outside the lock since the Windows heap is already thread-safe. CRITICAL_SECTION supports recursive acquisition, so nested calls from _ExFreePoolWithTracking through UntrackAllocation and TrackFreedMemoryLocked are safe.

Add TrackingLock to GLOBAL_STATE, initialized in GetGlobalState() and
cleaned up in CleanupHeap(). All linked list operations (insert, remove,
traverse) on MemoryAllocations and FreedMemoryList are now protected.
HeapAlloc/HeapFree for user memory stay outside the lock since the
Windows heap is already thread-safe. CRITICAL_SECTION supports recursive
acquisition, so nested calls from _ExFreePoolWithTracking through
UntrackAllocation and TrackFreedMemoryLocked are safe.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@TorinKS TorinKS merged commit cc286ad into main Mar 22, 2026
2 checks passed
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.

1 participant