Clean up a bit.

This commit is contained in:
Bob Nystrom
2015-06-26 23:01:07 -07:00
parent 8c538e4048
commit 7baef81a4e
6 changed files with 16 additions and 20 deletions
-4
View File
@@ -46,10 +46,6 @@ char* readFile(const char* path)
void setRootDirectory(const char* path)
{
if (rootDirectory != NULL)
{
free((void*)rootDirectory);
}
rootDirectory = path;
}
+3 -2
View File
@@ -26,10 +26,11 @@ void runFile(WrenBindForeignMethodFn bindForeign, const char* path)
{
// Use the directory where the file is as the root to resolve imports
// relative to.
char* root = NULL;
const char* lastSlash = strrchr(path, '/');
if (lastSlash != NULL)
{
char* root = (char*)malloc(lastSlash - path + 2);
root = (char*)malloc(lastSlash - path + 2);
memcpy(root, path, lastSlash - path + 1);
root[lastSlash - path + 1] = '\0';
setRootDirectory(root);
@@ -48,7 +49,7 @@ void runFile(WrenBindForeignMethodFn bindForeign, const char* path)
wrenFreeVM(vm);
free(source);
setRootDirectory(NULL);
free(root);
// Exit with an error code if the script failed.
if (result == WREN_RESULT_COMPILE_ERROR) exit(65); // EX_DATAERR.