Skip to content

Commit 702261a

Browse files
committed
fix ui.show_file_text_viewer not freeing memory or reporting an error if OOM happens
1 parent f355844 commit 702261a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

arm9/source/lua/gm9ui.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,27 @@ static int ui_show_file_text_viewer(lua_State* L) {
227227
// and FileTextViewer calls the above function
228228

229229
char* text = malloc(STD_BUFFER_SIZE);
230-
if (!text) return false;
230+
if (!text) {
231+
return luaL_error(L, "could not allocate memory");
232+
};
231233

232234
u32 flen = FileGetData(path, text, STD_BUFFER_SIZE - 1, 0);
233235

234236
text[flen] = '\0';
235237
u32 len = (ptrdiff_t)memchr(text, '\0', flen + 1) - (ptrdiff_t)text;
236238

237239
if (!(ValidateText(text, len))) {
240+
free(text);
238241
return luaL_error(L, "text validation failed");
239242
}
240243

241244
if (!(MemTextViewer(text, len, 1, false))) {
245+
free(text);
242246
return luaL_error(L, "failed to run MemTextViewer");
243247
}
244248

249+
free(text);
250+
245251
return 0;
246252
}
247253

0 commit comments

Comments
 (0)