Commit c26172f3 authored by dubroy@chromium.org's avatar dubroy@chromium.org

Fix leak in ComponentLoader.

Ensure that DictionaryValues are deleted when removing from the
list of registered component extensions.

BUG=none
TEST=unit_tests ComponentLoader*

Review URL: http://codereview.chromium.org/8598016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110713 0039d316-1c4b-4281-b951-d872f2087c98
parent e0c06c7a
...@@ -42,6 +42,7 @@ ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service, ...@@ -42,6 +42,7 @@ ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service,
} }
ComponentLoader::~ComponentLoader() { ComponentLoader::~ComponentLoader() {
ClearAllRegistered();
} }
void ComponentLoader::LoadAll() { void ComponentLoader::LoadAll() {
...@@ -65,6 +66,16 @@ DictionaryValue* ComponentLoader::ParseManifest( ...@@ -65,6 +66,16 @@ DictionaryValue* ComponentLoader::ParseManifest(
return static_cast<DictionaryValue*>(manifest.release()); return static_cast<DictionaryValue*>(manifest.release());
} }
void ComponentLoader::ClearAllRegistered() {
for (RegisteredComponentExtensions::iterator it =
component_extensions_.begin();
it != component_extensions_.end(); ++it) {
delete it->manifest;
}
component_extensions_.clear();
}
const Extension* ComponentLoader::Add( const Extension* ComponentLoader::Add(
int manifest_resource_id, int manifest_resource_id,
const FilePath& root_directory) { const FilePath& root_directory) {
...@@ -135,7 +146,8 @@ void ComponentLoader::Remove(const FilePath& root_directory) { ...@@ -135,7 +146,8 @@ void ComponentLoader::Remove(const FilePath& root_directory) {
if (it == component_extensions_.end()) if (it == component_extensions_.end())
return; return;
const DictionaryValue* manifest = it->manifest; // The list owns the dictionary, so it must be deleted after removal.
scoped_ptr<const DictionaryValue> manifest(it->manifest);
// Remove the extension from the list of registered extensions. // Remove the extension from the list of registered extensions.
*it = component_extensions_.back(); *it = component_extensions_.back();
......
...@@ -67,9 +67,7 @@ class ComponentLoader : public content::NotificationObserver { ...@@ -67,9 +67,7 @@ class ComponentLoader : public content::NotificationObserver {
DictionaryValue* ParseManifest(const std::string& manifest_contents) const; DictionaryValue* ParseManifest(const std::string& manifest_contents) const;
// Clear the list of registered extensions. // Clear the list of registered extensions.
void ClearAllRegistered() { void ClearAllRegistered();
component_extensions_.clear();
}
private: private:
// Information about a registered component extension. // Information about a registered component extension.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment