summaryrefslogtreecommitdiff
path: root/platform/x11/godot_x11.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/x11/godot_x11.cpp')
-rw-r--r--platform/x11/godot_x11.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/platform/x11/godot_x11.cpp b/platform/x11/godot_x11.cpp
index 3241cbcbf9..755ef7a84f 100644
--- a/platform/x11/godot_x11.cpp
+++ b/platform/x11/godot_x11.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -43,7 +43,8 @@ int main(int argc, char *argv[]) {
setlocale(LC_CTYPE, "");
char *cwd = (char *)malloc(PATH_MAX);
- getcwd(cwd, PATH_MAX);
+ ERR_FAIL_COND_V(!cwd, ERR_OUT_OF_MEMORY);
+ char *ret = getcwd(cwd, PATH_MAX);
Error err = Main::setup(argv[0], argc - 1, &argv[1]);
if (err != OK) {
@@ -55,7 +56,11 @@ int main(int argc, char *argv[]) {
os.run(); // it is actually the OS that decides how to run
Main::cleanup();
- chdir(cwd);
+ if (ret) { // Previous getcwd was successful
+ if (chdir(cwd) != 0) {
+ ERR_PRINT("Couldn't return to previous working directory.");
+ }
+ }
free(cwd);
return os.get_exit_code();