From aaabf35f802867886a5ea735136d9431a7c0862d Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 30 Jun 2014 18:11:48 -0400 Subject: [PATCH] Bug 1028588 - Fix dangerous public destructors in libpref/ - r=bsmedberg --- modules/libpref/public/Preferences.h | 3 ++- modules/libpref/src/Preferences.cpp | 10 ++++++---- modules/libpref/src/nsPrefBranch.h | 15 +++++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/modules/libpref/public/Preferences.h b/modules/libpref/public/Preferences.h index 37a57df3c02b..751e8b231267 100644 --- a/modules/libpref/public/Preferences.h +++ b/modules/libpref/public/Preferences.h @@ -50,7 +50,6 @@ public: NS_DECL_NSIOBSERVER Preferences(); - virtual ~Preferences(); nsresult Init(); @@ -353,6 +352,8 @@ public: static nsresult SetFloat(const char* aPref, float aValue); protected: + virtual ~Preferences(); + nsresult NotifyServiceObservers(const char *aSubject); /** * Reads the default pref file or, if that failed, try to save a new one. diff --git a/modules/libpref/src/Preferences.cpp b/modules/libpref/src/Preferences.cpp index 9b48912c9ad8..aa419e708d1c 100644 --- a/modules/libpref/src/Preferences.cpp +++ b/modules/libpref/src/Preferences.cpp @@ -128,6 +128,10 @@ public: class ValueObserver MOZ_FINAL : public nsIObserver, public ValueObserverHashKey { + ~ValueObserver() { + Preferences::RemoveObserver(this, mPrefName.get()); + } + public: NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER @@ -135,10 +139,6 @@ public: ValueObserver(const char *aPref, PrefChangedFunc aCallback) : ValueObserverHashKey(aPref, aCallback) { } - ~ValueObserver() { - Preferences::RemoveObserver(this, mPrefName.get()); - } - void AppendClosure(void *aClosure) { mClosures.AppendElement(aClosure); } @@ -229,6 +229,8 @@ Preferences::SizeOfIncludingThisAndOtherStuff(mozilla::MallocSizeOf aMallocSizeO class PreferenceServiceReporter MOZ_FINAL : public nsIMemoryReporter { + ~PreferenceServiceReporter() {} + public: NS_DECL_ISUPPORTS NS_DECL_NSIMEMORYREPORTER diff --git a/modules/libpref/src/nsPrefBranch.h b/modules/libpref/src/nsPrefBranch.h index 9db210df5637..ed629e686309 100644 --- a/modules/libpref/src/nsPrefBranch.h +++ b/modules/libpref/src/nsPrefBranch.h @@ -187,7 +187,6 @@ public: NS_DECL_NSIOBSERVER nsPrefBranch(const char *aPrefRoot, bool aDefaultBranch); - virtual ~nsPrefBranch(); int32_t GetRootLength() { return mPrefRootLength; } @@ -198,6 +197,8 @@ public: size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf); protected: + virtual ~nsPrefBranch(); + nsPrefBranch() /* disallow use of this constructer */ { } @@ -232,7 +233,6 @@ class nsPrefLocalizedString : public nsIPrefLocalizedString, { public: nsPrefLocalizedString(); - virtual ~nsPrefLocalizedString(); NS_DECL_ISUPPORTS NS_FORWARD_NSISUPPORTSSTRING(mUnicodeString->) @@ -241,6 +241,8 @@ public: nsresult Init(); private: + virtual ~nsPrefLocalizedString(); + NS_IMETHOD GetData(char16_t**); NS_IMETHOD SetData(const char16_t* aData); NS_IMETHOD SetDataWithLength(uint32_t aLength, const char16_t *aData); @@ -254,11 +256,12 @@ class nsRelativeFilePref : public nsIRelativeFilePref public: NS_DECL_ISUPPORTS NS_DECL_NSIRELATIVEFILEPREF - - nsRelativeFilePref(); - virtual ~nsRelativeFilePref(); - + + nsRelativeFilePref(); + private: + virtual ~nsRelativeFilePref(); + nsCOMPtr mFile; nsCString mRelativeToKey; };