summaryrefslogtreecommitdiff
path: root/main/main.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-03-10 15:27:09 +0100
committerRémi Verschelde <rverschelde@gmail.com>2022-03-11 09:13:11 +0100
commit768f9422bc3b1349729b8a50feb8c0797003aee9 (patch)
treeccc2863deb916a604b39cf67f897b32edcdfc4da /main/main.cpp
parent259114e9e0d5bb01d023ad978e06ed14ca785b1d (diff)
Convert uses of `DirAccess *` to `DirAccessRef` to prevent memleaks
`DirAccess *` needs to be deleted manually, and this is often forgotten especially when doing early returns with `ERR_FAIL_COND`. `DirAccessRef` is deleted automatically when it goes out of scope. Co-authored-by: bruvzg <7645683+bruvzg@users.noreply.github.com>
Diffstat (limited to 'main/main.cpp')
-rw-r--r--main/main.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/main/main.cpp b/main/main.cpp
index 97794ece1a..ccd48a9343 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -2099,9 +2099,8 @@ bool Main::start() {
checked_paths.insert(path);
// Create the module documentation directory if it doesn't exist
- DirAccess *da = DirAccess::create_for_path(path);
+ DirAccessRef da = DirAccess::create_for_path(path);
err = da->make_dir_recursive(path);
- memdelete(da);
ERR_FAIL_COND_V_MSG(err != OK, false, "Error: Can't create directory: " + path + ": " + itos(err));
print_line("Loading docs from: " + path);
@@ -2112,9 +2111,8 @@ bool Main::start() {
String index_path = doc_tool_path.plus_file("doc/classes");
// Create the main documentation directory if it doesn't exist
- DirAccess *da = DirAccess::create_for_path(index_path);
+ DirAccessRef da = DirAccess::create_for_path(index_path);
err = da->make_dir_recursive(index_path);
- memdelete(da);
ERR_FAIL_COND_V_MSG(err != OK, false, "Error: Can't create index directory: " + index_path + ": " + itos(err));
print_line("Loading classes from: " + index_path);
@@ -2452,15 +2450,13 @@ bool Main::start() {
int sep = local_game_path.rfind("/");
if (sep == -1) {
- DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
local_game_path = da->get_current_dir().plus_file(local_game_path);
- memdelete(da);
} else {
- DirAccess *da = DirAccess::open(local_game_path.substr(0, sep));
+ DirAccessRef da = DirAccess::open(local_game_path.substr(0, sep));
if (da) {
local_game_path = da->get_current_dir().plus_file(
local_game_path.substr(sep + 1, local_game_path.length()));
- memdelete(da);
}
}
}