diff --git a/src/cli/io.c b/src/cli/io.c index f31ddc01..5727d270 100644 --- a/src/cli/io.c +++ b/src/cli/io.c @@ -46,6 +46,10 @@ char* readFile(const char* path) void setRootDirectory(const char* path) { + if (rootDirectory != NULL) + { + free((void*)rootDirectory); + } rootDirectory = path; } diff --git a/src/cli/vm.c b/src/cli/vm.c index 3a62d0f7..a682911d 100644 --- a/src/cli/vm.c +++ b/src/cli/vm.c @@ -48,6 +48,7 @@ void runFile(WrenBindForeignMethodFn bindForeign, const char* path) wrenFreeVM(vm); free(source); + setRootDirectory(NULL); // Exit with an error code if the script failed. if (result == WREN_RESULT_COMPILE_ERROR) exit(65); // EX_DATAERR.