Fix memory leak in lua selection iterate

Iterating over a large set of locations in a selection caused a memory leak.
Lua couldn't do garbage collection in the middle of the iterator function,
so it eventually ran out of space, and just quietly dropped stuff.
This commit is contained in:
Pasi Kallinen
2025-04-20 20:19:01 +03:00
parent 8f38267775
commit 079566cad9

View File

@@ -925,7 +925,7 @@ l_selection_iterate(lua_State *L)
if (argc == 2 && lua_type(L, 2) == LUA_TFUNCTION) {
sel = l_selection_check(L, 1);
selection_getbounds(sel, &rect);
for (y = rect.ly; y <= rect.hy; y++)
for (y = rect.ly; y <= rect.hy; y++) {
for (x = max(1,rect.lx); x <= rect.hx; x++)
if (selection_getpoint(x, y, sel)) {
coordxy tmpx = x, tmpy = y;
@@ -939,6 +939,8 @@ l_selection_iterate(lua_State *L)
goto out;
}
}
lua_gc(L, LUA_GCCOLLECT, 0);
}
} else {
nhl_error(L, "wrong parameters");
/*NOTREACHED*/