fixed huge memory leak in wxFileDialog (closes patch 544060)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15214 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-04-20 11:10:19 +00:00
parent e94ff4cbf1
commit 7a82dabcc7
2 changed files with 48 additions and 41 deletions

View File

@@ -201,8 +201,8 @@ wxGTK:
- support for more SGI hardware (12-bit mode among others)
- fixed wxDC::Blit() to honour source DC's logical coordinates
- implemented wxIdleEvent::RequestMore() for simple background tasks
(unlike thread work)
- implemented wxChoice::Delete()
- fixed bad memory leak in wxFileDialog (Chris Elliott)
wxHTML:

View File

@@ -67,17 +67,16 @@
#include <direct.h>
#endif
# include <time.h>
#include <time.h>
#include <unistd.h>
//-----------------------------------------------------------------------------
// wxFileData
//-----------------------------------------------------------------------------
class wxFileData : public wxObject
class wxFileData
{
public:
wxFileData() { }
wxFileData( const wxString &name, const wxString &fname );
wxString GetName() const;
wxString GetFullName() const;
@@ -103,8 +102,6 @@ private:
bool m_isDir;
bool m_isLink;
bool m_isExe;
DECLARE_DYNAMIC_CLASS(wxFileData);
};
//-----------------------------------------------------------------------------
@@ -124,6 +121,8 @@ public:
long style = wxLC_LIST,
const wxValidator &validator = wxDefaultValidator,
const wxString &name = wxT("filelist") );
virtual ~wxFileCtrl();
void ChangeToListMode();
void ChangeToReportMode();
void ChangeToIconMode();
@@ -138,7 +137,6 @@ public:
void SetWild( const wxString &wild );
void GetDir( wxString &dir );
void OnListDeleteItem( wxListEvent &event );
void OnListDeleteAllItems( wxListEvent &event );
void OnListEndLabelEdit( wxListEvent &event );
// Associate commonly used UI controls with wxFileCtrl so that they can be
@@ -148,6 +146,9 @@ public:
void SetNewDirControl(wxWindow *ctrl) { m_newDirControl = ctrl; }
private:
void FreeItemData(const wxListItem& item);
void FreeAllItemsData();
wxString m_dirName;
bool m_showHidden;
wxString m_wild;
@@ -391,8 +392,6 @@ extern bool wxIsDriveAvailable(const wxString& dirName);
// wxFileData
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxFileData,wxObject);
wxFileData::wxFileData( const wxString &name, const wxString &fname )
{
m_name = name;
@@ -584,7 +583,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl,wxListCtrl);
BEGIN_EVENT_TABLE(wxFileCtrl,wxListCtrl)
EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem)
EVT_LIST_DELETE_ALL_ITEMS(-1, wxFileCtrl::OnListDeleteAllItems)
EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit)
END_EVENT_TABLE()
@@ -680,7 +678,9 @@ void wxFileCtrl::UpdateFiles()
name_col_width = GetColumnWidth( 0 );
}
FreeAllItemsData();
ClearAll();
if (my_style & wxLC_REPORT)
{
if (name_col_width < 140) name_col_width = 140;
@@ -884,13 +884,18 @@ void wxFileCtrl::GetDir( wxString &dir )
dir = m_dirName;
}
void wxFileCtrl::OnListDeleteItem( wxListEvent &event )
void wxFileCtrl::FreeItemData(const wxListItem& item)
{
wxFileData *fd = (wxFileData*)event.m_item.m_data;
wxFileData *fd = (wxFileData*)item.m_data;
delete fd;
}
void wxFileCtrl::OnListDeleteAllItems( wxListEvent &WXUNUSED(event) )
void wxFileCtrl::OnListDeleteItem( wxListEvent &event )
{
FreeItemData(event.m_item);
}
void wxFileCtrl::FreeAllItemsData()
{
wxListItem item;
item.m_mask = wxLIST_MASK_DATA;
@@ -899,10 +904,7 @@ void wxFileCtrl::OnListDeleteAllItems( wxListEvent &WXUNUSED(event) )
while ( item.m_itemId != -1 )
{
GetItem( item );
wxFileData *fd = (wxFileData*)item.m_data;
delete fd;
item.m_data = 0;
SetItem( item );
FreeItemData(item);
item.m_itemId = GetNextItem( item.m_itemId, wxLIST_NEXT_ALL );
}
}
@@ -950,6 +952,11 @@ void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event )
}
}
wxFileCtrl::~wxFileCtrl()
{
FreeAllItemsData();
}
//-----------------------------------------------------------------------------
// wxFileDialog
//-----------------------------------------------------------------------------