-
Notifications
You must be signed in to change notification settings - Fork 220
Open
Description
Issue
Calling of the constructors for the TMC2130 that create the software SPI instance create it using new. As there is no destructor specified for the class, deleting the TMC2130 class instance will leave you with a memory leak. The software SPI variable TMC_SW_SPI is never deleted, only set to nullptr on class instantiation.
TMCStepper/src/source/TMC2130Stepper.cpp
Line 23 in 74e8e68
| SW_SPIClass *SW_SPI_Obj = new SW_SPIClass(pinMOSI, pinMISO, pinSCK); |
Solution
Create a destructor for the TMC2130 class that checks if the instance exists and deletes it when it does.
## .\TMCStepper.h
virtual ~TMC2130Stepper()
## .\source\TMC2130Stepper.cpp
TMC2130Stepper::~TMC2130Stepper()
{
if (TMC_SW_SPI != nullptr) {
delete TMC_SW_SPI;
TMC_SW_SPI = nullptr;
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels