Missing virtual destructor for `Print` class

Open
#256 0 comments 0 reactions 0 assignees View on GitHub

@andreagilardoni is already working on this.

Since Sep 27, 2023.

  • #218 by @andreagilardoni — open

Assessment

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

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.

Description

bug
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

Dominant language
C++
Stars
306
Forks
150
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from arduino/ArduinoCore-API

All issues in arduino/ArduinoCore-API

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.