mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:25:52 +01:00
[PR #1698] image_memory: guard zero requests, make allocate strong-exception-safe, and free outside mutex #1712
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1712
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1698
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/image-memory-pool-guards📝 Commits (1)
68fd4dfimage_memory: guard zero requests, make allocate strong-exception-safe, and free outside mutex📊 Changes
2 files changed (+189 additions, -19 deletions)
View changed files
📝
runtime/src/image_memory.h(+59 -19)📝
runtime/test/image_memory_test.cpp(+130 -0)📄 Description
Item ID:
IMAGE-MEMORY-POOL-GUARDS-AND-EXCEPTION-SAFETYClaim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157274006
Summary
Hardens
BlockRangesandImageMemoryPoolinruntime/src/image_memory.hand adds regression coverage inruntime/test/image_memory_test.cpp:sizeor zeroalignmentupfront inImageMemoryPool::allocate: previously,size == 0oralignment == 0walked existing blocks, decremented the OOMskipcounter, calledallocate_(type, block_bytes)to request a new driver allocation, failedblock->ranges.allocate(...), and freed it while holdingmutex_.BlockRanges::release: ignoresize == 0early instead of mutating free-range maps.std::bad_allocinBlockRanges::allocateandBlockRanges::insert: extract the chosen free-piece nodes fromby_size_andby_offset_and roll back via no-throw node re-insertion if inserting the lead or tail remainder throws; clean upby_offset_ifby_size_.insertthrows.ImageMemoryPool::allocate: pre-allocate theRangewrapper and reservepool.blocksbefore mutating ranges or callingallocate_(), attach/commit only vianoexceptoperations, and releasememoryvia a scope guard declared outsidelocksofree_is always invoked aftermutex_is unlocked (matchingrelease()) on any failure orstd::bad_allocwithout leaking driver memory or corruptingstats().ranges.Verification
clang++ -std=c++20 -O2 -Wall -Wextra -Werror -pedantic -fsanitize=undefined -pthread runtime/test/image_memory_test.cpp-> exit 0, all checks pass, 0 warnings / 0 UBSan issues.Mutation check against unpatched
main(git show main:runtime/src/image_memory.hwith updatedimage_memory_test.cpp) -> exit 1 (30FAIL lines reproducing zero-request driver allocation, skip-window corruption,BlockRangescorruption, and driver memory / range / free-space leaks).python3 -I scripts/check_no_game_data.py runtime/src/image_memory.h runtime/test/image_memory_test.cpp-> OK.python3 -m compileall -q make_game.py tools testsandpython3 -I tests/test_text_write_line_endings.py-> OK (3/3).AI-assisted: yes
GPUs tested: none (CPU-only portable
image_memory_testwith counted fake allocations; no game files)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.