From 768f9422bc3b1349729b8a50feb8c0797003aee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 10 Mar 2022 15:27:09 +0100 Subject: 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> --- core/config/project_settings.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'core/config') diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 83f58311f1..09bcf26ef1 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -145,7 +145,7 @@ String ProjectSettings::localize_path(const String &p_path) const { return p_path.simplify_path(); } - DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + DirAccessRef dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); String path = p_path.replace("\\", "/").simplify_path(); @@ -153,8 +153,6 @@ String ProjectSettings::localize_path(const String &p_path) const { String cwd = dir->get_current_dir(); cwd = cwd.replace("\\", "/"); - memdelete(dir); - // Ensure that we end with a '/'. // This is important to ensure that we do not wrongly localize the resource path // in an absolute path that just happens to contain this string but points to a @@ -173,8 +171,6 @@ String ProjectSettings::localize_path(const String &p_path) const { return cwd.replace_first(res_path, "res://"); } else { - memdelete(dir); - int sep = path.rfind("/"); if (sep == -1) { return "res://" + path; @@ -541,7 +537,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b // Nothing was found, try to find a project file in provided path (`p_path`) // or, if requested (`p_upwards`) in parent directories. - DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + DirAccessRef d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); ERR_FAIL_COND_V_MSG(!d, ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_path + "'."); d->change_dir(p_path); @@ -573,8 +569,6 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b } } - memdelete(d); - if (!found) { return err; } -- cgit v1.2.3