diff options
author | mdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-14 20:48:55 +0000 |
---|---|---|
committer | mdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-14 20:48:55 +0000 |
commit | d8f977430b5e85b8489f7c39afc0afad06892672 (patch) | |
tree | d1489d03ddb0c96f43437b9caf01f029c1e03913 | |
parent | 4245ae4e0766915f2e5ef8f1ba411089bc261ba2 (diff) | |
download | chromium_src-d8f977430b5e85b8489f7c39afc0afad06892672.zip chromium_src-d8f977430b5e85b8489f7c39afc0afad06892672.tar.gz chromium_src-d8f977430b5e85b8489f7c39afc0afad06892672.tar.bz2 |
Linux: fix small memory leaks in passwords and exceptions dialog.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2817001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49724 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 32 insertions, 27 deletions
diff --git a/chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc b/chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc index 25d35c9..4495bdf 100644 --- a/chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc +++ b/chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc @@ -8,6 +8,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/stl_util-inl.h" #include "base/utf_string_conversions.h" #include "chrome/browser/gtk/gtk_tree.h" #include "chrome/browser/gtk/gtk_util.h" @@ -69,6 +70,7 @@ PasswordsExceptionsPageGtk::PasswordsExceptionsPageGtk(Profile* profile) } PasswordsExceptionsPageGtk::~PasswordsExceptionsPageGtk() { + STLDeleteElements(&exception_list_); } /////////////////////////////////////////////////////////////////////////////// @@ -112,9 +114,9 @@ void PasswordsExceptionsPageGtk::SetExceptionList( std::wstring languages = profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); gtk_list_store_clear(exception_list_store_); - exception_list_.resize(result.size()); + STLDeleteElements(&exception_list_); + exception_list_ = result; for (size_t i = 0; i < result.size(); ++i) { - exception_list_[i] = *result[i]; GtkTreeIter iter; gtk_list_store_insert_with_values(exception_list_store_, &iter, (gint) i, COL_SITE, @@ -143,7 +145,8 @@ void PasswordsExceptionsPageGtk::OnRemoveButtonClicked(GtkWidget* widget) { // Remove from GTK list, DB, and vector. gtk_list_store_remove(exception_list_store_, &child_iter); - GetPasswordStore()->RemoveLogin(exception_list_[index]); + GetPasswordStore()->RemoveLogin(*exception_list_[index]); + delete exception_list_[index]; exception_list_.erase(exception_list_.begin() + index); gtk_widget_set_sensitive(remove_all_button_, exception_list_.size() > 0); @@ -153,10 +156,9 @@ void PasswordsExceptionsPageGtk::OnRemoveAllButtonClicked(GtkWidget* widget) { // Remove from GTK list, DB, and vector. PasswordStore* store = GetPasswordStore(); gtk_list_store_clear(exception_list_store_); - for (size_t i = 0; i < exception_list_.size(); ++i) { - store->RemoveLogin(exception_list_[i]); - } - exception_list_.clear(); + for (size_t i = 0; i < exception_list_.size(); ++i) + store->RemoveLogin(*exception_list_[i]); + STLDeleteElements(&exception_list_); gtk_widget_set_sensitive(remove_all_button_, FALSE); } @@ -178,8 +180,8 @@ gint PasswordsExceptionsPageGtk::CompareSite(GtkTreeModel* model, int row2 = gtk_tree::GetRowNumForIter(model, b); PasswordsExceptionsPageGtk* page = reinterpret_cast<PasswordsExceptionsPageGtk*>(window); - return page->exception_list_[row1].origin.spec().compare( - page->exception_list_[row2].origin.spec()); + return page->exception_list_[row1]->origin.spec().compare( + page->exception_list_[row2]->origin.spec()); } void PasswordsExceptionsPageGtk::ExceptionListPopulater::populate() { diff --git a/chrome/browser/gtk/options/passwords_exceptions_page_gtk.h b/chrome/browser/gtk/options/passwords_exceptions_page_gtk.h index 3466412..e2d2d41 100644 --- a/chrome/browser/gtk/options/passwords_exceptions_page_gtk.h +++ b/chrome/browser/gtk/options/passwords_exceptions_page_gtk.h @@ -30,7 +30,8 @@ class PasswordsExceptionsPageGtk { // The password store associated with the currently active profile. PasswordStore* GetPasswordStore(); - // Sets the exception list contents to the given data. + // Sets the exception list contents to the given data. We take ownership of + // the PasswordForms in the vector. void SetExceptionList(const std::vector<webkit_glue::PasswordForm*>& result); CHROMEGTK_CALLBACK_0(PasswordsExceptionsPageGtk, void, OnRemoveButtonClicked); @@ -84,7 +85,7 @@ class PasswordsExceptionsPageGtk { GtkWidget* page_; Profile* profile_; - std::vector<webkit_glue::PasswordForm> exception_list_; + std::vector<webkit_glue::PasswordForm*> exception_list_; DISALLOW_COPY_AND_ASSIGN(PasswordsExceptionsPageGtk); }; diff --git a/chrome/browser/gtk/options/passwords_page_gtk.cc b/chrome/browser/gtk/options/passwords_page_gtk.cc index 39a92e3..75ee9a2 100644 --- a/chrome/browser/gtk/options/passwords_page_gtk.cc +++ b/chrome/browser/gtk/options/passwords_page_gtk.cc @@ -9,6 +9,7 @@ #include "app/gtk_util.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/stl_util-inl.h" #include "base/utf_string_conversions.h" #include "chrome/browser/gtk/gtk_tree.h" #include "chrome/browser/gtk/gtk_util.h" @@ -99,6 +100,7 @@ PasswordsPageGtk::PasswordsPageGtk(Profile* profile) } PasswordsPageGtk::~PasswordsPageGtk() { + STLDeleteElements(&password_list_); } /////////////////////////////////////////////////////////////////////////////// @@ -156,9 +158,9 @@ void PasswordsPageGtk::SetPasswordList( std::wstring languages = profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); gtk_list_store_clear(password_list_store_); - password_list_.resize(result.size()); + STLDeleteElements(&password_list_); + password_list_ = result; for (size_t i = 0; i < result.size(); ++i) { - password_list_[i] = *result[i]; GtkTreeIter iter; gtk_list_store_insert_with_values(password_list_store_, &iter, (gint) i, COL_SITE, @@ -188,11 +190,11 @@ void PasswordsPageGtk::OnRemoveButtonClicked(GtkWidget* widget) { // Remove from GTK list, DB, and vector. gtk_list_store_remove(password_list_store_, &child_iter); - GetPasswordStore()->RemoveLogin(password_list_[index]); + GetPasswordStore()->RemoveLogin(*password_list_[index]); + delete password_list_[index]; password_list_.erase(password_list_.begin() + index); - gtk_widget_set_sensitive(remove_all_button_, - password_list_.size() > 0); + gtk_widget_set_sensitive(remove_all_button_, password_list_.size() > 0); } void PasswordsPageGtk::OnRemoveAllButtonClicked(GtkWidget* widget) { @@ -231,10 +233,9 @@ void PasswordsPageGtk::OnRemoveAllConfirmResponse(GtkWidget* confirm, // Remove from GTK list, DB, and vector. PasswordStore* store = GetPasswordStore(); gtk_list_store_clear(password_list_store_); - for (size_t i = 0; i < password_list_.size(); ++i) { - store->RemoveLogin(password_list_[i]); - } - password_list_.clear(); + for (size_t i = 0; i < password_list_.size(); ++i) + store->RemoveLogin(*password_list_[i]); + STLDeleteElements(&password_list_); gtk_widget_set_sensitive(remove_all_button_, FALSE); } @@ -259,7 +260,7 @@ void PasswordsPageGtk::OnShowPasswordButtonClicked(GtkWidget* widget) { gint index = gtk_tree::GetTreeSortChildRowNumForPath( password_list_sort_, path); gtk_tree_path_free(path); - std::string pass = UTF16ToUTF8(password_list_[index].password_value); + std::string pass = UTF16ToUTF8(password_list_[index]->password_value); gtk_label_set_text(GTK_LABEL(password_), pass.c_str()); gtk_button_set_label(GTK_BUTTON(show_password_button_), l10n_util::GetStringUTF8(IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON).c_str()); @@ -289,8 +290,8 @@ gint PasswordsPageGtk::CompareSite(GtkTreeModel* model, int row1 = gtk_tree::GetRowNumForIter(model, a); int row2 = gtk_tree::GetRowNumForIter(model, b); PasswordsPageGtk* page = reinterpret_cast<PasswordsPageGtk*>(window); - return page->password_list_[row1].origin.spec().compare( - page->password_list_[row2].origin.spec()); + return page->password_list_[row1]->origin.spec().compare( + page->password_list_[row2]->origin.spec()); } // static @@ -300,8 +301,8 @@ gint PasswordsPageGtk::CompareUsername(GtkTreeModel* model, int row1 = gtk_tree::GetRowNumForIter(model, a); int row2 = gtk_tree::GetRowNumForIter(model, b); PasswordsPageGtk* page = reinterpret_cast<PasswordsPageGtk*>(window); - return page->password_list_[row1].username_value.compare( - page->password_list_[row2].username_value); + return page->password_list_[row1]->username_value.compare( + page->password_list_[row2]->username_value); } void PasswordsPageGtk::PasswordListPopulater::populate() { diff --git a/chrome/browser/gtk/options/passwords_page_gtk.h b/chrome/browser/gtk/options/passwords_page_gtk.h index 59de866..328ce35 100644 --- a/chrome/browser/gtk/options/passwords_page_gtk.h +++ b/chrome/browser/gtk/options/passwords_page_gtk.h @@ -27,7 +27,8 @@ class PasswordsPageGtk { // The password store associated with the currently active profile. PasswordStore* GetPasswordStore(); - // Sets the password list contents to the given data. + // Sets the password list contents to the given data. We take ownership of + // the PasswordForms in the vector. void SetPasswordList(const std::vector<webkit_glue::PasswordForm*>& result); CHROMEGTK_CALLBACK_0(PasswordsPageGtk, void, OnRemoveButtonClicked); @@ -88,7 +89,7 @@ class PasswordsPageGtk { GtkWidget* page_; Profile* profile_; - std::vector<webkit_glue::PasswordForm> password_list_; + std::vector<webkit_glue::PasswordForm*> password_list_; DISALLOW_COPY_AND_ASSIGN(PasswordsPageGtk); }; |