fix for memory leaks (patch 885242)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25550 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2004-02-07 13:19:18 +00:00
parent 6e76b35d73
commit 811697104b
3 changed files with 52 additions and 23 deletions

View File

@@ -156,6 +156,7 @@ wxGTK:
- use same average character width as other ports when calculating dialog units - use same average character width as other ports when calculating dialog units
- fixed mouse wheel handling under GTK2 (Hugh Fisher) - fixed mouse wheel handling under GTK2 (Hugh Fisher)
- wxNotebook::HitTest() implemented (Daniel Lundqvist) - wxNotebook::HitTest() implemented (Daniel Lundqvist)
- memory leaks fixes in wxFileDialog (John Labenski)
wxMac: wxMac:

View File

@@ -148,11 +148,14 @@ public:
}; };
// Full copy constructor // Full copy constructor
wxFileData( const wxFileData& fileData ); wxFileData( const wxFileData& fileData ) { Copy(fileData); }
// Create a filedata from this information // Create a filedata from this information
wxFileData( const wxString &filePath, const wxString &fileName, wxFileData( const wxString &filePath, const wxString &fileName,
fileType type, int image_id ); fileType type, int image_id );
// make a full copy of the other wxFileData
void Copy( const wxFileData &other );
// (re)read the extra data about the file from the system // (re)read the extra data about the file from the system
void ReadData(); void ReadData();
@@ -206,6 +209,9 @@ public:
// initialize a wxListItem attributes // initialize a wxListItem attributes
void MakeItem( wxListItem &item ); void MakeItem( wxListItem &item );
wxFileData& operator = (const wxFileData& fd) { Copy(fd); return *this; }
private: private:
wxString m_fileName; wxString m_fileName;
wxString m_filePath; wxString m_filePath;
@@ -253,6 +259,7 @@ public:
wxString GetDir() const { return m_dirName; } wxString GetDir() const { return m_dirName; }
void OnListDeleteItem( wxListEvent &event ); void OnListDeleteItem( wxListEvent &event );
void OnListDeleteAllItems( wxListEvent &event );
void OnListEndLabelEdit( wxListEvent &event ); void OnListEndLabelEdit( wxListEvent &event );
void OnListColClick( wxListEvent &event ); void OnListColClick( wxListEvent &event );
@@ -261,7 +268,7 @@ public:
wxFileData::fileListFieldType GetSortField() const { return m_sort_field; } wxFileData::fileListFieldType GetSortField() const { return m_sort_field; }
protected: protected:
void FreeItemData(const wxListItem& item); void FreeItemData(wxListItem& item);
void FreeAllItemsData(); void FreeAllItemsData();
wxString m_dirName; wxString m_dirName;

View File

@@ -1,4 +1,4 @@
///////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Name: filedlgg.cpp // Name: filedlgg.cpp
// Purpose: wxGenericFileDialog // Purpose: wxGenericFileDialog
// Author: Robert Roebling // Author: Robert Roebling
@@ -154,17 +154,6 @@ extern size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, w
// wxFileData // wxFileData
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
wxFileData::wxFileData( const wxFileData& fileData )
{
m_fileName = fileData.GetFileName();
m_filePath = fileData.GetFilePath();
m_size = fileData.GetSize();
m_dateTime = fileData.GetDateTime();
m_permissions = fileData.GetPermissions();
m_type = fileData.GetType();
m_image = GetImageId();
}
wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, fileType type, int image_id ) wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, fileType type, int image_id )
{ {
m_fileName = fileName; m_fileName = fileName;
@@ -175,6 +164,17 @@ wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, file
ReadData(); ReadData();
} }
void wxFileData::Copy( const wxFileData& fileData )
{
m_fileName = fileData.GetFileName();
m_filePath = fileData.GetFilePath();
m_size = fileData.GetSize();
m_dateTime = fileData.GetDateTime();
m_permissions = fileData.GetPermissions();
m_type = fileData.GetType();
m_image = GetImageId();
}
void wxFileData::ReadData() void wxFileData::ReadData()
{ {
if (IsDrive()) if (IsDrive())
@@ -358,6 +358,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl,wxListCtrl)
BEGIN_EVENT_TABLE(wxFileCtrl,wxListCtrl) BEGIN_EVENT_TABLE(wxFileCtrl,wxListCtrl)
EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem) EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem)
EVT_LIST_DELETE_ALL_ITEMS(-1, wxFileCtrl::OnListDeleteAllItems)
EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit) EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit)
EVT_LIST_COL_CLICK(-1, wxFileCtrl::OnListColClick) EVT_LIST_COL_CLICK(-1, wxFileCtrl::OnListColClick)
END_EVENT_TABLE() END_EVENT_TABLE()
@@ -488,7 +489,6 @@ void wxFileCtrl::UpdateFiles()
wxBusyCursor bcur; // this may take a while... wxBusyCursor bcur; // this may take a while...
FreeAllItemsData();
DeleteAllItems(); DeleteAllItems();
wxListItem item; wxListItem item;
@@ -505,8 +505,10 @@ void wxFileCtrl::UpdateFiles()
for (n=0; n<count; n++) for (n=0; n<count; n++)
{ {
wxFileData *fd = new wxFileData(paths[n], names[n], wxFileData::is_drive, icons[n]); wxFileData *fd = new wxFileData(paths[n], names[n], wxFileData::is_drive, icons[n]);
Add(fd, item); if (Add(fd, item) != -1)
item.m_itemId++; item.m_itemId++;
else
delete fd;
} }
} }
else else
@@ -520,8 +522,10 @@ void wxFileCtrl::UpdateFiles()
if (p.IsEmpty()) p = wxT("/"); if (p.IsEmpty()) p = wxT("/");
#endif // __UNIX__ #endif // __UNIX__
wxFileData *fd = new wxFileData(p, wxT(".."), wxFileData::is_dir, wxFileIconsTable::folder); wxFileData *fd = new wxFileData(p, wxT(".."), wxFileData::is_dir, wxFileIconsTable::folder);
Add(fd, item); if (Add(fd, item) != -1)
item.m_itemId++; item.m_itemId++;
else
delete fd;
} }
wxString dirname(m_dirName); wxString dirname(m_dirName);
@@ -547,8 +551,11 @@ void wxFileCtrl::UpdateFiles()
while (cont) while (cont)
{ {
wxFileData *fd = new wxFileData(dirPrefix + f, f, wxFileData::is_dir, wxFileIconsTable::folder); wxFileData *fd = new wxFileData(dirPrefix + f, f, wxFileData::is_dir, wxFileIconsTable::folder);
Add(fd, item); if (Add(fd, item) != -1)
item.m_itemId++; item.m_itemId++;
else
delete fd;
cont = dir.GetNext(&f); cont = dir.GetNext(&f);
} }
@@ -562,8 +569,11 @@ void wxFileCtrl::UpdateFiles()
while (cont) while (cont)
{ {
wxFileData *fd = new wxFileData(dirPrefix + f, f, wxFileData::is_file, wxFileIconsTable::file); wxFileData *fd = new wxFileData(dirPrefix + f, f, wxFileData::is_file, wxFileIconsTable::file);
Add(fd, item); if (Add(fd, item) != -1)
item.m_itemId++; item.m_itemId++;
else
delete fd;
cont = dir.GetNext(&f); cont = dir.GetNext(&f);
} }
} }
@@ -626,6 +636,8 @@ void wxFileCtrl::MakeDir()
EnsureVisible( id ); EnsureVisible( id );
EditLabel( id ); EditLabel( id );
} }
else
delete fd;
} }
void wxFileCtrl::GoToParentDir() void wxFileCtrl::GoToParentDir()
@@ -673,10 +685,15 @@ void wxFileCtrl::GoToDir( const wxString &dir )
EnsureVisible( 0 ); EnsureVisible( 0 );
} }
void wxFileCtrl::FreeItemData(const wxListItem& item) void wxFileCtrl::FreeItemData(wxListItem& item)
{
if ( item.m_data )
{ {
wxFileData *fd = (wxFileData*)item.m_data; wxFileData *fd = (wxFileData*)item.m_data;
delete fd; delete fd;
item.m_data = 0;
}
} }
void wxFileCtrl::OnListDeleteItem( wxListEvent &event ) void wxFileCtrl::OnListDeleteItem( wxListEvent &event )
@@ -684,6 +701,11 @@ void wxFileCtrl::OnListDeleteItem( wxListEvent &event )
FreeItemData(event.m_item); FreeItemData(event.m_item);
} }
void wxFileCtrl::OnListDeleteAllItems( wxListEvent &event )
{
FreeAllItemsData();
}
void wxFileCtrl::FreeAllItemsData() void wxFileCtrl::FreeAllItemsData()
{ {
wxListItem item; wxListItem item;
@@ -797,7 +819,6 @@ void wxFileCtrl::SortItems(wxFileData::fileListFieldType field, bool foward)
wxFileCtrl::~wxFileCtrl() wxFileCtrl::~wxFileCtrl()
{ {
FreeAllItemsData();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------