From bfd1162cdcecbc0db6cd4763dd475f2d093dc404 Mon Sep 17 00:00:00 2001 From: j4nk Date: Tue, 23 May 2023 08:19:01 -0400 Subject: [PATCH] Fixed memory leak caused by nonexistent file --- Makefile | 4 ++-- main.c | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index cdbff56..d71980a 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,10 @@ BIN=main DEBUG=-g 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 - $(CC) $(INC) $(CLIB) -c -o $@ $< + $(CC) -g $(INC) $(CLIB) -c -o $@ $< test: $(CC) $(INC) $(CLIB) test.c -o test $(DEBUG) diff --git a/main.c b/main.c index f90db9f..85eafbc 100644 --- a/main.c +++ b/main.c @@ -51,6 +51,10 @@ int main(int argc, char* argv[]) { fprintf(stderr, "Error: Could not open file: %s\n", argv[argc-1]); return EXIT_FAILURE; break; + case OCT_INVALID_ARGUMENT: + fprintf(stderr, "Error: unknown argument\n"); + return EXIT_FAILURE; + break; case OCT_HELP: usage(); return EXIT_SUCCESS; @@ -122,6 +126,10 @@ int process_args(int argc, char* argv[]) { } 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()) { return 0; } @@ -132,7 +140,7 @@ int initialize_everything(char* lua_file) { } luaL_openlibs(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_call(L, 0, 1); int type = lua_tointeger(L, -1);