From: Vadim Zeitlin Date: Sat, 7 Feb 2004 13:19:18 +0000 (+0000) Subject: fix for memory leaks (patch 885242) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/811697104b7e2f30a28feb4171c1c408f0459966 fix for memory leaks (patch 885242) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25550 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index ebac708f26..93bda7d04d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -156,6 +156,7 @@ wxGTK: - use same average character width as other ports when calculating dialog units - fixed mouse wheel handling under GTK2 (Hugh Fisher) - wxNotebook::HitTest() implemented (Daniel Lundqvist) +- memory leaks fixes in wxFileDialog (John Labenski) wxMac: diff --git a/include/wx/generic/filedlgg.h b/include/wx/generic/filedlgg.h index 22b50f9800..d8bea303d7 100644 --- a/include/wx/generic/filedlgg.h +++ b/include/wx/generic/filedlgg.h @@ -148,11 +148,14 @@ public: }; // Full copy constructor - wxFileData( const wxFileData& fileData ); + wxFileData( const wxFileData& fileData ) { Copy(fileData); } // Create a filedata from this information wxFileData( const wxString &filePath, const wxString &fileName, 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 void ReadData(); @@ -206,6 +209,9 @@ public: // initialize a wxListItem attributes void MakeItem( wxListItem &item ); + + wxFileData& operator = (const wxFileData& fd) { Copy(fd); return *this; } + private: wxString m_fileName; wxString m_filePath; @@ -253,6 +259,7 @@ public: wxString GetDir() const { return m_dirName; } void OnListDeleteItem( wxListEvent &event ); + void OnListDeleteAllItems( wxListEvent &event ); void OnListEndLabelEdit( wxListEvent &event ); void OnListColClick( wxListEvent &event ); @@ -261,7 +268,7 @@ public: wxFileData::fileListFieldType GetSortField() const { return m_sort_field; } protected: - void FreeItemData(const wxListItem& item); + void FreeItemData(wxListItem& item); void FreeAllItemsData(); wxString m_dirName; diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index 6f301a8f23..bcb63b71d0 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -1,4 +1,4 @@ -///////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// // Name: filedlgg.cpp // Purpose: wxGenericFileDialog // Author: Robert Roebling @@ -154,17 +154,6 @@ extern size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, w // 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 ) { m_fileName = fileName; @@ -175,6 +164,17 @@ wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, file 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() { if (IsDrive()) @@ -358,6 +358,7 @@ 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) EVT_LIST_COL_CLICK(-1, wxFileCtrl::OnListColClick) END_EVENT_TABLE() @@ -488,7 +489,6 @@ void wxFileCtrl::UpdateFiles() wxBusyCursor bcur; // this may take a while... - FreeAllItemsData(); DeleteAllItems(); wxListItem item; @@ -505,8 +505,10 @@ void wxFileCtrl::UpdateFiles() for (n=0; n