Fix memory leak when not finishing iteration started by wxFindFirstFile().

Memory allocated by wxFindFirstFile() was only freed when no more files could
be found by wxFindNextFile(), resulting in a memory leak if the iteration was
never finished.

Closes #4631.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75975 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-02-22 14:54:24 +00:00
parent 1911811fe6
commit b1a92006b9

View File

@@ -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<wxDir> 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;
}