Fixed memory leak caused by nonexistent file

This commit is contained in:
j4nk 2023-05-23 08:19:01 -04:00
parent 3d2b590389
commit bfd1162cdc
2 changed files with 11 additions and 3 deletions

View File

@ -5,10 +5,10 @@ BIN=main
DEBUG=-g DEBUG=-g
open_card_table: main.o oct_networking.o open_card_table: main.o oct_networking.o
$(CC) $(INC) $(CLIB) -o open_card_table main.o oct_networking.o $(CC) -g $(INC) $(CLIB) -o open_card_table main.o oct_networking.o
%.o: %.c %.o: %.c
$(CC) $(INC) $(CLIB) -c -o $@ $< $(CC) -g $(INC) $(CLIB) -c -o $@ $<
test: test:
$(CC) $(INC) $(CLIB) test.c -o test $(DEBUG) $(CC) $(INC) $(CLIB) test.c -o test $(DEBUG)

10
main.c
View File

@ -51,6 +51,10 @@ int main(int argc, char* argv[]) {
fprintf(stderr, "Error: Could not open file: %s\n", argv[argc-1]); fprintf(stderr, "Error: Could not open file: %s\n", argv[argc-1]);
return EXIT_FAILURE; return EXIT_FAILURE;
break; break;
case OCT_INVALID_ARGUMENT:
fprintf(stderr, "Error: unknown argument\n");
return EXIT_FAILURE;
break;
case OCT_HELP: case OCT_HELP:
usage(); usage();
return EXIT_SUCCESS; return EXIT_SUCCESS;
@ -122,6 +126,10 @@ int process_args(int argc, char* argv[]) {
} }
int initialize_everything(char* lua_file) { int initialize_everything(char* lua_file) {
// Check if file exists
if (access(lua_file, F_OK) != 0) {
return OCT_LUA_FILE_NOT_FOUND;
}
if (!oct_tb_sprite_list_initialize()) { if (!oct_tb_sprite_list_initialize()) {
return 0; return 0;
} }
@ -132,7 +140,7 @@ int initialize_everything(char* lua_file) {
} }
luaL_openlibs(L); luaL_openlibs(L);
oct_tb_initialize_lua(L); oct_tb_initialize_lua(L);
if (luaL_dofile(L, lua_file)) return OCT_LUA_FILE_NOT_FOUND; //if (luaL_dofile(L, lua_file)) return OCT_LUA_FILE_NOT_FOUND;
lua_getglobal(L, "oct_init"); lua_getglobal(L, "oct_init");
lua_call(L, 0, 1); lua_call(L, 0, 1);
int type = lua_tointeger(L, -1); int type = lua_tointeger(L, -1);