fix: squirrel scanline/border callback memory leak (#2825) - #2965
Open
joshgoebel wants to merge 1 commit into
Open
fix: squirrel scanline/border callback memory leak (#2825)#2965joshgoebel wants to merge 1 commit into
joshgoebel wants to merge 1 commit into
Conversation
joshgoebel
force-pushed
the
fix-squirrel-memleak
branch
from
June 27, 2026 17:04
300858a to
95eead7
Compare
The callSquirrelIntCallback function was missing a pop for the root table reference after successful sq_call, causing it to accumulate on the VM stack with each scn() or bdr() callback invocation. Added the missing sq_poptop(vm) to maintain proper stack balance.
joshgoebel
force-pushed
the
fix-squirrel-memleak
branch
from
June 27, 2026 17:21
95eead7 to
f4cc5fe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a memory leak in
callSquirrelIntCallback()where the root table reference and function lookup were never popped from the Squirrel VM stack on success paths. At 60fps, this accumulates stack entries on everyscn()orbdr()callback, causing memory growth and slowdowns.The Fix
Added
sq_poptop(vm)cleanup for both success and error paths to balance the 2 pushes (sq_pushroottable+sq_getresult) with corresponding pops.Before: 2 pushes, only popped in error path — leak on every successful call
After: 2 pushes balanced by 2 pops on all paths
Related Issue
Fixes nesbox/TIC-80#2825