diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 063e932c40..4c9c702eaf 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -37,6 +37,7 @@ #include "wx/filename.h" #include "wx/dir.h" +#include "wx/scopedptr.h" #include "wx/tokenzr.h" // there are just too many of those... @@ -1309,7 +1310,7 @@ bool wxGetTempFileName(const wxString& prefix, wxString& buf) // Get first file name matching given wild card. -static wxDir *gs_dir = NULL; +static wxScopedPtr gs_dir; static wxString gs_dirPath; wxString wxFindFirstFile(const wxString& spec, int flags) @@ -1320,8 +1321,7 @@ wxString wxFindFirstFile(const wxString& spec, int flags) if ( !wxEndsWithPathSeparator(gs_dirPath ) ) gs_dirPath << wxFILE_SEP_PATH; - delete gs_dir; // can be NULL, this is ok - gs_dir = new wxDir(gs_dirPath); + gs_dir.reset(new wxDir(gs_dirPath)); if ( !gs_dir->IsOpened() ) { @@ -1340,10 +1340,7 @@ wxString wxFindFirstFile(const wxString& spec, int flags) wxString result; gs_dir->GetFirst(&result, wxFileNameFromPath(spec), dirFlags); if ( result.empty() ) - { - wxDELETE(gs_dir); return result; - } return gs_dirPath + result; } @@ -1354,10 +1351,7 @@ wxString wxFindNextFile() wxString result; if ( !gs_dir->GetNext(&result) || result.empty() ) - { - wxDELETE(gs_dir); return result; - } return gs_dirPath + result; }