arduino / arduino/ArduinoCore-API

Missing virtual destructor for `Print` class

Open
#256 0 comments 0 reactions 0 assignees Claimed by @andreagilardoni View on GitHub
bug
Dominant language
C++
Stars
306
Forks
150
PR merge metrics
No merged PRs in 30d

Description

### Description

Missing virtual destructor - memory leak and UB

### Environment

First found on R4, but it is general

### Current behavior

Warning while compiling sketch, possible UB.

```
packages/arduino/hardware/renesas_uno/1.5.0/libraries/WiFiS3/src/Modem.cpp: In destructor 'ModemClass::~ModemClass()':
packages/arduino/hardware/renesas_uno/1.5.0/libraries/WiFiS3/src/Modem.cpp:27:14: warning: deleting object of polymorphic
class type 'UART' which has non-virtual destructor might cause undefined behavior [-Wdelete-non-virtual-dtor]
delete _serial;
```
ModemClass extends Serial which extends Print.

### Expected behavior

no warnings

### Additional information

This class is very base class of all streams and other i/o components.

https://github.com/arduino/ArduinoCore-API/blob/4a02bfc0a924e1fec34c3bb82ffd5dfba7643a0c/api/Print.h#L35

Contributor guide

No contributing guide indexed for this repository

Research direction

Read the referenced api/Print.h declaration and review linked pull request #218 to understand the proposed change. Done means the Modem.cpp example no longer produces the non-virtual-destructor warning or the associated undefined-behavior concern.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, embedded-iot
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.