Merge pull request #1039 from takase1121/PR/font-retrieve-leak

fix memory leak and wrong check in font_retrieve
This commit is contained in:
Jefferson González 2022-06-15 16:36:06 -04:00 committed by GitHub
commit 0c7a132ec5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -60,16 +60,16 @@ static int f_font_load(lua_State *L) {
static bool font_retrieve(lua_State* L, RenFont** fonts, int idx) { static bool font_retrieve(lua_State* L, RenFont** fonts, int idx) {
memset(fonts, 0, sizeof(RenFont*)*FONT_FALLBACK_MAX); memset(fonts, 0, sizeof(RenFont*)*FONT_FALLBACK_MAX);
if (lua_type(L, 1) != LUA_TTABLE) { if (lua_type(L, idx) != LUA_TTABLE) {
fonts[0] = *(RenFont**)luaL_checkudata(L, idx, API_TYPE_FONT); fonts[0] = *(RenFont**)luaL_checkudata(L, idx, API_TYPE_FONT);
return false; return false;
} }
int i = 0; int len = luaL_len(L, idx); len = len > FONT_FALLBACK_MAX ? FONT_FALLBACK_MAX : len;
do { for (int i = 0; i < len; i++) {
lua_rawgeti(L, idx, i+1); lua_rawgeti(L, idx, i+1);
fonts[i] = !lua_isnil(L, -1) ? *(RenFont**)luaL_checkudata(L, -1, API_TYPE_FONT) : NULL; fonts[i] = *(RenFont**) luaL_checkudata(L, -1, API_TYPE_FONT);
lua_pop(L, 1); lua_pop(L, 1);
} while (fonts[i] && i++ < FONT_FALLBACK_MAX); }
return true; return true;
} }