Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1588)

Unified Diff: chrome/browser/ui/webui/help/version_updater_win.cc

Issue 15649007: Attempt to fix use-after-free in VersionUpdaterWin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Set -> Create Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/help/version_updater_win.cc
diff --git a/chrome/browser/ui/webui/help/version_updater_win.cc b/chrome/browser/ui/webui/help/version_updater_win.cc
index 2df0593bea11fcccea45945b581d95b808f34031..a3b1b8f92fa8707f44bfb0c487ae2fa5e8accac5 100644
--- a/chrome/browser/ui/webui/help/version_updater_win.cc
+++ b/chrome/browser/ui/webui/help/version_updater_win.cc
@@ -59,8 +59,11 @@ class VersionUpdaterWin : public VersionUpdater,
// result case can now be completeb on the UI thread.
void GotInstalledVersion(const Version& version);
- // Little helper function to reset google_updater_.
- void SetGoogleUpdater();
+ // Little helper function to create google_updater_.
+ void CreateGoogleUpdater();
+
+ // Helper function to clear google_updater_.
+ void ClearGoogleUpdater();
// Returns a window that can be used for elevation.
HWND GetElevationParent();
@@ -121,14 +124,13 @@ class VersionReader
VersionUpdaterWin::VersionUpdaterWin()
: weak_factory_(this) {
- SetGoogleUpdater();
+ CreateGoogleUpdater();
}
VersionUpdaterWin::~VersionUpdaterWin() {
// The Google Updater will hold a pointer to the listener until it reports
// status, so that pointer must be cleared when the listener is destoyed.
- if (google_updater_)
- google_updater_->set_status_listener(NULL);
+ ClearGoogleUpdater();
}
void VersionUpdaterWin::CheckForUpdate(const StatusCallback& callback) {
@@ -144,7 +146,7 @@ void VersionUpdaterWin::CheckForUpdate(const StatusCallback& callback) {
!base::win::UserAccountControlIsEnabled())) {
// This could happen if the page got refreshed after results were returned.
if (!google_updater_)
- SetGoogleUpdater();
+ CreateGoogleUpdater();
UpdateStatus(UPGRADE_CHECK_STARTED, GOOGLE_UPDATE_NO_ERROR, string16());
// Specify false to not upgrade yet.
google_updater_->CheckForUpdate(false, GetElevationParent());
@@ -159,7 +161,7 @@ void VersionUpdaterWin::OnReportResults(
GoogleUpdateUpgradeResult result, GoogleUpdateErrorCode error_code,
const string16& error_message, const string16& version) {
// Drop the last reference to the object so that it gets cleaned up here.
- google_updater_ = NULL;
+ ClearGoogleUpdater();
UpdateStatus(result, error_code, error_message);
}
@@ -188,7 +190,7 @@ void VersionUpdaterWin::UpdateStatus(GoogleUpdateUpgradeResult result,
content::RecordAction(
UserMetricsAction("UpgradeCheck_UpgradeIsAvailable"));
DCHECK(!google_updater_); // Should have been nulled out already.
- SetGoogleUpdater();
+ CreateGoogleUpdater();
UpdateStatus(UPGRADE_STARTED, GOOGLE_UPDATE_NO_ERROR, string16());
// Specify true to upgrade now.
google_updater_->CheckForUpdate(true, GetElevationParent());
@@ -256,11 +258,19 @@ void VersionUpdaterWin::GotInstalledVersion(const Version& version) {
}
}
-void VersionUpdaterWin::SetGoogleUpdater() {
+void VersionUpdaterWin::CreateGoogleUpdater() {
+ ClearGoogleUpdater();
google_updater_ = new GoogleUpdate();
google_updater_->set_status_listener(this);
}
+void VersionUpdaterWin::ClearGoogleUpdater() {
+ if (google_updater_) {
+ google_updater_->set_status_listener(NULL);
+ google_updater_ = NULL;
+ }
+}
+
BOOL CALLBACK WindowEnumeration(HWND window, LPARAM param) {
if (IsWindowVisible(window)) {
HWND* returned_window = reinterpret_cast<HWND*>(param);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698