Avoid calling virtual functions from constructors and destructors

Virtual functions are resolved statically (not dynamically) in
constructors and destructors for the same class. The call should be made
explicitly static by qualifying it using the scope resolution operator.
pull/15401/head
Mingjie Shen 2023-04-18 23:12:39 -04:00
parent 975dfcf968
commit 4c3928ecf4
5 changed files with 7 additions and 7 deletions

View File

@ -77,7 +77,7 @@ TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, cont
TLSSocketWrapper::~TLSSocketWrapper()
{
if (_transport) {
close();
TLSSocketWrapper::close();
}
mbedtls_entropy_free(&_entropy);

View File

@ -138,7 +138,7 @@ int CAN::filter(unsigned int id, unsigned int mask, CANFormat format, int handle
void CAN::attach(Callback<void()> func, IrqType type)
{
lock();
CAN::lock();
if (func) {
// lock deep sleep only the first time
if (!_irq[(CanIrqType)type]) {
@ -154,7 +154,7 @@ void CAN::attach(Callback<void()> func, IrqType type)
_irq[(CanIrqType)type] = nullptr;
can_irq_set(&_can, (CanIrqType)type, 0);
}
unlock();
CAN::unlock();
}
void CAN::_irq_handler(uintptr_t context, CanIrqType type)

View File

@ -148,12 +148,12 @@ void SPI::_do_construct()
SPI::~SPI()
{
lock();
SPI::lock();
/* Make sure a stale pointer isn't left in peripheral's owner field */
if (_peripheral->owner == this) {
_peripheral->owner = nullptr;
}
unlock();
SPI::unlock();
}
SPI::spi_peripheral_s *SPI::_lookup(SPI::SPIName name)

View File

@ -34,7 +34,7 @@ Dir::Dir(FileSystem *fs, const char *path)
Dir::~Dir()
{
if (_fs) {
close();
Dir::close();
}
}

View File

@ -34,7 +34,7 @@ File::File(FileSystem *fs, const char *path, int flags)
File::~File()
{
if (_fs) {
close();
File::close();
}
}