Base classes should have virtual destructors
Each base class in service/common/bluetooth now has a virtual
destructor. This fixes memory delete issues that were exposed
when running the unit tests with ASAN enabled.
Test: Running unit tests with ASAN enabled
Change-Id: Ie944eb80784de4ebac3c7276fabed6acb5fec6c0
diff --git a/service/common/bluetooth/advertise_data.h b/service/common/bluetooth/advertise_data.h
index f5f5b5c..0eb2bc1 100644
--- a/service/common/bluetooth/advertise_data.h
+++ b/service/common/bluetooth/advertise_data.h
@@ -41,7 +41,7 @@
// Default constructor initializes all fields to be empty/false.
AdvertiseData();
AdvertiseData(const AdvertiseData& other);
- ~AdvertiseData() = default;
+ virtual ~AdvertiseData() = default;
// Returns true if the advertising data is formatted correctly according to
// the TLV format.
diff --git a/service/common/bluetooth/advertise_settings.h b/service/common/bluetooth/advertise_settings.h
index bd3764d..6a533dd 100644
--- a/service/common/bluetooth/advertise_settings.h
+++ b/service/common/bluetooth/advertise_settings.h
@@ -69,7 +69,7 @@
// TX power level: TX_POWER_LEVEL_MEDIUM
// connectable: true
AdvertiseSettings();
- ~AdvertiseSettings() = default;
+ virtual ~AdvertiseSettings() = default;
// Returns the advertise mode.
Mode mode() const { return mode_; }
diff --git a/service/common/bluetooth/characteristic.h b/service/common/bluetooth/characteristic.h
index a68270a..ba7328a 100644
--- a/service/common/bluetooth/characteristic.h
+++ b/service/common/bluetooth/characteristic.h
@@ -35,7 +35,7 @@
permissions_(permissions),
descriptors_(descriptors){};
Characteristic& operator=(const Characteristic& other);
- ~Characteristic() = default;
+ virtual ~Characteristic() = default;
// Comparison function and operator.
bool Equals(const Characteristic& other) const;
diff --git a/service/common/bluetooth/descriptor.h b/service/common/bluetooth/descriptor.h
index 90c021d..35fe53e 100644
--- a/service/common/bluetooth/descriptor.h
+++ b/service/common/bluetooth/descriptor.h
@@ -26,7 +26,7 @@
Descriptor& operator=(const Descriptor& other);
Descriptor(uint16_t handle, const UUID& uuid, uint16_t permissions)
: handle_(handle), uuid_(uuid), permissions_(permissions){};
- ~Descriptor() = default;
+ virtual ~Descriptor() = default;
// Comparison function and operator.
bool Equals(const Descriptor& other) const;
diff --git a/service/common/bluetooth/scan_filter.h b/service/common/bluetooth/scan_filter.h
index 74cfcb8..d4c87dd 100644
--- a/service/common/bluetooth/scan_filter.h
+++ b/service/common/bluetooth/scan_filter.h
@@ -27,7 +27,7 @@
class ScanFilter {
public:
ScanFilter() = default;
- ~ScanFilter() = default;
+ virtual ~ScanFilter() = default;
// Copy constructor and assignment operator.
ScanFilter(const ScanFilter& other);
diff --git a/service/common/bluetooth/scan_result.h b/service/common/bluetooth/scan_result.h
index 67240c2..150ad4e 100644
--- a/service/common/bluetooth/scan_result.h
+++ b/service/common/bluetooth/scan_result.h
@@ -30,7 +30,7 @@
ScanResult(const std::string& device_address,
const std::vector<uint8_t>& scan_record, int rssi);
ScanResult() = default;
- ~ScanResult() = default;
+ virtual ~ScanResult() = default;
// Returns the remote BD_ADDR associated with this scan result.
const std::string& device_address() const { return device_address_; }
diff --git a/service/common/bluetooth/scan_settings.h b/service/common/bluetooth/scan_settings.h
index 02d7eb8..da907b5 100644
--- a/service/common/bluetooth/scan_settings.h
+++ b/service/common/bluetooth/scan_settings.h
@@ -116,7 +116,7 @@
ScanSettings(Mode mode, CallbackTypeBitField callback_type,
ResultType result_type, base::TimeDelta report_delay_ms,
MatchMode match_mode, MatchCount match_count_per_filter);
- ~ScanSettings() = default;
+ virtual ~ScanSettings() = default;
// Returns the scan mode.
Mode mode() const { return mode_; }
diff --git a/service/common/bluetooth/service.h b/service/common/bluetooth/service.h
index 1949546..b3ce0ea 100644
--- a/service/common/bluetooth/service.h
+++ b/service/common/bluetooth/service.h
@@ -35,7 +35,7 @@
characteristics_(characteristics),
included_services_(included_services){};
Service& operator=(const Service& other);
- ~Service() = default;
+ virtual ~Service() = default;
// Comparison function and operator.
bool Equals(const Service& other) const;
diff --git a/service/common/bluetooth/uuid.h b/service/common/bluetooth/uuid.h
index 57dec0a..034654c 100644
--- a/service/common/bluetooth/uuid.h
+++ b/service/common/bluetooth/uuid.h
@@ -46,6 +46,7 @@
// Construct a Bluetooth 'base' UUID.
UUID();
+ virtual ~UUID() = default;
// BlueDroid constructor.
explicit UUID(const bt_uuid_t& uuid);