summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-08 13:16:30 +0000
committerbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-08 13:16:30 +0000
commit8af06d38223973a64ed1c88709a4764f51bb5fe6 (patch)
tree93ad9091e4a3b129cfdbd1d621f372d44b1bbb3d
parent198339b0f1370a5b490caba7bb2ee2c2e8584deb (diff)
downloadchromium_src-8af06d38223973a64ed1c88709a4764f51bb5fe6.zip
chromium_src-8af06d38223973a64ed1c88709a4764f51bb5fe6.tar.gz
chromium_src-8af06d38223973a64ed1c88709a4764f51bb5fe6.tar.bz2
Fix memory leak in ExtensionPrefTest
BUG=65642 TEST=look at valgrind build bots, introduced new unit test Review URL: http://codereview.chromium.org/5511010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68590 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_prefs.cc8
-rw-r--r--chrome/browser/extensions/extension_prefs_unittest.cc35
-rw-r--r--tools/heapcheck/suppressions.txt14
-rw-r--r--tools/valgrind/memcheck/suppressions.txt8
4 files changed, 40 insertions, 25 deletions
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc
index c36a599..cc1beb8 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -1253,6 +1253,7 @@ void ExtensionPrefs::UpdatePrefStore(const std::string& pref_key) {
void ExtensionPrefs::SetExtensionControlledPref(const std::string& extension_id,
const std::string& pref_key,
Value* value) {
+ scoped_ptr<Value> scoped_value(value);
DCHECK(pref_service()->FindPreference(pref_key.c_str()))
<< "Extension controlled preference key " << pref_key
<< " not registered.";
@@ -1271,14 +1272,15 @@ void ExtensionPrefs::SetExtensionControlledPref(const std::string& extension_id,
Value* oldValue = NULL;
extension_preferences->GetWithoutPathExpansion(pref_key, &oldValue);
- bool modified = !Value::Equals(oldValue, value);
+ bool modified = !Value::Equals(oldValue, scoped_value.get());
if (!modified)
return;
- if (value == NULL)
+ if (scoped_value.get() == NULL)
extension_preferences->RemoveWithoutPathExpansion(pref_key, NULL);
else
- extension_preferences->SetWithoutPathExpansion(pref_key, value);
+ extension_preferences->SetWithoutPathExpansion(pref_key,
+ scoped_value.release());
pref_service()->ScheduleSavePersistentPrefs();
UpdatePrefStore(pref_key);
diff --git a/chrome/browser/extensions/extension_prefs_unittest.cc b/chrome/browser/extensions/extension_prefs_unittest.cc
index 05ccb42..d5ebe02 100644
--- a/chrome/browser/extensions/extension_prefs_unittest.cc
+++ b/chrome/browser/extensions/extension_prefs_unittest.cc
@@ -858,3 +858,38 @@ class ExtensionPrefsReenableExt
}
};
TEST_F(ExtensionPrefsDisableExt, ExtensionPrefsReenableExt) {}
+
+// Mock class to test whether objects are deleted correctly.
+class MockStringValue : public StringValue {
+ public:
+ explicit MockStringValue(const std::string& in_value)
+ : StringValue(in_value) {
+ }
+ virtual ~MockStringValue() {
+ Die();
+ }
+ MOCK_METHOD0(Die, void());
+};
+
+class ExtensionPrefsSetExtensionControlledPref
+ : public ExtensionPrefsPreferencesBase {
+ public:
+ virtual void Initialize() {
+ MockStringValue* v1 = new MockStringValue("https://www.chromium.org");
+ MockStringValue* v2 = new MockStringValue("https://www.chromium.org");
+ // Ownership is taken, value shall not be deleted.
+ EXPECT_CALL(*v1, Die()).Times(0);
+ InstallExtControlledPref(ext1_, kPref1, v1);
+ testing::Mock::VerifyAndClearExpectations(v1);
+ // Make sure there is no memory leak and both values are deleted.
+ EXPECT_CALL(*v2, Die()).Times(1);
+ EXPECT_CALL(*v1, Die()).Times(1);
+ InstallExtControlledPref(ext1_, kPref1, v2);
+ prefs_.RecreateExtensionPrefs();
+ }
+
+ virtual void Verify() {
+ }
+};
+TEST_F(ExtensionPrefsSetExtensionControlledPref,
+ ExtensionPrefsSetExtensionControlledPref) {}
diff --git a/tools/heapcheck/suppressions.txt b/tools/heapcheck/suppressions.txt
index 02529c7..655990d 100644
--- a/tools/heapcheck/suppressions.txt
+++ b/tools/heapcheck/suppressions.txt
@@ -1055,20 +1055,6 @@
fun:testing::Test::Run
}
{
- bug_65642a
- Heapcheck:Leak
- ...
- fun:ExtensionPrefsNotifyWhenNeeded::Initialize
- fun:ExtensionPrefsTest::SetUp
-}
-{
- bug_65642b
- Heapcheck:Leak
- fun:Value::CreateStringValue
- fun:ExtensionPrefsNotifyWhenNeeded::Initialize
- fun:ExtensionPrefsTest::SetUp
-}
-{
bug_65664a
Heapcheck:Leak
fun:webkit_glue::BufferedResourceLoaderTest::Initialize
diff --git a/tools/valgrind/memcheck/suppressions.txt b/tools/valgrind/memcheck/suppressions.txt
index 4538a8d..5d95744 100644
--- a/tools/valgrind/memcheck/suppressions.txt
+++ b/tools/valgrind/memcheck/suppressions.txt
@@ -3399,14 +3399,6 @@
fun:_ZN13ResourcesUtil18GetThemeResourceIdERKSs
}
{
- bug_65642
- Memcheck:Leak
- fun:_Znw*
- fun:_ZN5Value17CreateStringValueERKSs
- fun:_ZN30ExtensionPrefsNotifyWhenNeeded10InitializeEv
- fun:_ZN18ExtensionPrefsTest5SetUpEv
-}
-{
bug_65664a
Memcheck:Leak
fun:_Znw*