platform2: Enforce virtual destructors on base classes There have been a number of memory leak issues due to absence of virtual destructors on base classes. Swept through the following targets: buffet, libchromeos, webserver. For every class defined, I did one of the following three things: 1. If the class is not meant to be derived from, marked it as 'final'. 2. If classes derived from a particular base class are not meant to be deleted through the base class, marked the base class's destructor as 'protected'. 3. Otherwise made the base class's destructor virtual. BUG=None TEST=`FEATURES=test emerge-link libchromeos webserver buffet` Change-Id: I4d909399896d025c39980c9546b79b145614fc47 Reviewed-on: https://chromium-review.googlesource.com/273000 Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org> Tested-by: Alex Vakulenko <avakulenko@chromium.org> Reviewed-by: Vitaly Buka <vitalybuka@chromium.org> Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/base_api_handler.cc b/buffet/base_api_handler.cc index ce08bd1..69ed67c 100644 --- a/buffet/base_api_handler.cc +++ b/buffet/base_api_handler.cc
@@ -14,7 +14,7 @@ // Helps to get parameters from native_types::Object representing // CommandInstance parameters. -class ParametersReader { +class ParametersReader final { public: explicit ParametersReader(const native_types::Object* parameters) : parameters_{parameters} {}
diff --git a/buffet/buffet_client.cc b/buffet/buffet_client.cc index ef4bf03..8408a46 100644 --- a/buffet/buffet_client.cc +++ b/buffet/buffet_client.cc
@@ -139,7 +139,7 @@ return val; } -class Daemon : public chromeos::DBusDaemon { +class Daemon final : public chromeos::DBusDaemon { public: Daemon() = default;
diff --git a/buffet/commands/command_definition.h b/buffet/commands/command_definition.h index 3328a94..a5e2916 100644 --- a/buffet/commands/command_definition.h +++ b/buffet/commands/command_definition.h
@@ -19,7 +19,7 @@ // constraints. See comments for CommandDefinitions::LoadCommands for the // detailed description of what command categories are and what they are used // for. -class CommandDefinition { +class CommandDefinition final { public: struct Visibility { Visibility() = default;
diff --git a/buffet/commands/command_dictionary.h b/buffet/commands/command_dictionary.h index 7668fba..97ab596 100644 --- a/buffet/commands/command_dictionary.h +++ b/buffet/commands/command_dictionary.h
@@ -30,7 +30,7 @@ // the map) is a compound name in a form of "package_name.command_name", // where "package_name" is a name of command package such as "base", "printers", // and others. So the full command name could be "base.reboot", for example. -class CommandDictionary { +class CommandDictionary final { public: CommandDictionary() = default;
diff --git a/buffet/commands/command_queue.h b/buffet/commands/command_queue.h index 9178c8a..db6707c 100644 --- a/buffet/commands/command_queue.h +++ b/buffet/commands/command_queue.h
@@ -66,7 +66,7 @@ // Returns current time. base::Time Now() const; - // Overrided value to be returned from Now(). + // Overridden value to be returned from Now(). base::Time test_now_; // ID-to-CommandInstance map.
diff --git a/buffet/commands/dbus_command_dispatcher.h b/buffet/commands/dbus_command_dispatcher.h index ab63a6c..e9f5003 100644 --- a/buffet/commands/dbus_command_dispatcher.h +++ b/buffet/commands/dbus_command_dispatcher.h
@@ -28,7 +28,7 @@ // update the command handling progress. Once command is handled, // DBusCommandProxy::Done() is called and the command is removed from the // command queue and D-Bus ExportedObjectManager. -class DBusCommandDispacher { +class DBusCommandDispacher final { public: explicit DBusCommandDispacher(const base::WeakPtr< chromeos::dbus_utils::ExportedObjectManager>& object_manager);
diff --git a/buffet/commands/schema_utils.h b/buffet/commands/schema_utils.h index 625b854..59e3b39 100644 --- a/buffet/commands/schema_utils.h +++ b/buffet/commands/schema_utils.h
@@ -43,7 +43,7 @@ // is inherited or overridden, while |is_inherited| can be used to identify // if the attribute was inherited (true) or overridden (false). template<typename T> -class InheritableAttribute { +class InheritableAttribute final { public: InheritableAttribute() = default; explicit InheritableAttribute(T val)
diff --git a/buffet/device_registration_info.h b/buffet/device_registration_info.h index 7732da4..1314d5f 100644 --- a/buffet/device_registration_info.h +++ b/buffet/device_registration_info.h
@@ -55,7 +55,7 @@ const std::shared_ptr<chromeos::http::Transport>& transport, bool notifications_enabled); - virtual ~DeviceRegistrationInfo(); + ~DeviceRegistrationInfo() override; // Add callback to listen for changes in registration status. void AddOnRegistrationChangedCallback(
diff --git a/buffet/main.cc b/buffet/main.cc index a4ecf59..c7d44d0 100644 --- a/buffet/main.cc +++ b/buffet/main.cc
@@ -21,7 +21,7 @@ namespace buffet { -class Daemon : public DBusServiceDaemon { +class Daemon final : public DBusServiceDaemon { public: Daemon(const base::FilePath& config_path, const base::FilePath& state_path,
diff --git a/buffet/notification/xmpp_channel.h b/buffet/notification/xmpp_channel.h index 8db127e..4afb5df 100644 --- a/buffet/notification/xmpp_channel.h +++ b/buffet/notification/xmpp_channel.h
@@ -31,7 +31,7 @@ XmppChannel(const std::string& account, const std::string& access_token, const scoped_refptr<base::TaskRunner>& task_runner); - virtual ~XmppChannel() = default; + ~XmppChannel() override = default; // Overrides from NotificationChannel. std::string GetName() const override;
diff --git a/buffet/notification/xmpp_stream_parser.h b/buffet/notification/xmpp_stream_parser.h index 6bb39c7..9ff9200 100644 --- a/buffet/notification/xmpp_stream_parser.h +++ b/buffet/notification/xmpp_stream_parser.h
@@ -47,6 +47,9 @@ std::map<std::string, std::string> attributes) = 0; virtual void OnStreamEnd(const std::string& node_name) = 0; virtual void OnStanza(std::unique_ptr<XmlNode> stanza) = 0; + + protected: + virtual ~Delegate() = default; }; explicit XmppStreamParser(Delegate* delegate);
diff --git a/buffet/storage_impls.h b/buffet/storage_impls.h index 7f205da..6bdf251 100644 --- a/buffet/storage_impls.h +++ b/buffet/storage_impls.h
@@ -17,7 +17,7 @@ class FileStorage : public StorageInterface { public: explicit FileStorage(const base::FilePath& file_path); - virtual ~FileStorage() = default; + ~FileStorage() override = default; std::unique_ptr<base::DictionaryValue> Load() override; bool Save(const base::DictionaryValue& config) override; @@ -30,7 +30,7 @@ class MemStorage : public StorageInterface { public: MemStorage() = default; - virtual ~MemStorage() = default; + ~MemStorage() override = default; std::unique_ptr<base::DictionaryValue> Load() override; bool Save(const base::DictionaryValue& config) override;
diff --git a/buffet/test_daemon/main.cc b/buffet/test_daemon/main.cc index 0da72c2..64c0c00 100644 --- a/buffet/test_daemon/main.cc +++ b/buffet/test_daemon/main.cc
@@ -72,7 +72,7 @@ } // anonymous namespace -class Daemon : public chromeos::DBusDaemon { +class Daemon final : public chromeos::DBusDaemon { public: Daemon() = default;