Skip to content

fix: squirrel scanline/border callback memory leak (#2825) - #2965

Open
joshgoebel wants to merge 1 commit into
nesbox:mainfrom
joshgoebel:fix-squirrel-memleak
Open

fix: squirrel scanline/border callback memory leak (#2825)#2965
joshgoebel wants to merge 1 commit into
nesbox:mainfrom
joshgoebel:fix-squirrel-memleak

Conversation

@joshgoebel

Copy link
Copy Markdown
Collaborator

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 every scn() or bdr() 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_get result) 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

@joshgoebel
joshgoebel force-pushed the fix-squirrel-memleak branch from 300858a to 95eead7 Compare June 27, 2026 17:04
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
joshgoebel force-pushed the fix-squirrel-memleak branch from 95eead7 to f4cc5fe Compare June 27, 2026 17:21
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.

Squirrel scanline interrupt memory leak

2 participants