[Cleanup] Fix lots of missing delete calls to free memory

In a lot of places an object was allocated on the heap, but not always it was deleted thus leading to memory leaks.
This commit is contained in:
TD-er
2021-11-04 12:19:00 +01:00
parent 57e58740f2
commit 94221de5f6
28 changed files with 260 additions and 112 deletions
+16 -4
View File
@@ -77,13 +77,25 @@ struct C018_data_struct {
_baudrate = baudrate;
// FIXME TD-er: Make force SW serial a proper setting.
if (C018_easySerial != nullptr) {
delete C018_easySerial;
}
C018_easySerial = new (std::nothrow) ESPeasySerial(static_cast<ESPEasySerialPort>(port), serial_rx, serial_tx, false, 64);
if (C018_easySerial != nullptr) {
myLora = new rn2xx3(*C018_easySerial);
myLora->setAsyncMode(true);
myLora->setLastUsedJoinMode(joinIsOTAA);
triggerAutobaud();
if (myLora != nullptr) {
delete myLora;
}
myLora = new (std::nothrow) rn2xx3(*C018_easySerial);
if (myLora == nullptr) {
delete C018_easySerial;
C018_easySerial = nullptr;
} else {
myLora->setAsyncMode(true);
myLora->setLastUsedJoinMode(joinIsOTAA);
triggerAutobaud();
}
}
return isInitialized();
}
+1 -1
View File
@@ -226,7 +226,7 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
addLog(LOG_LEVEL_INFO, F("INIT: IR RX"));
addLog(LOG_LEVEL_INFO, F("IR lib Version: " _IRREMOTEESP8266_VERSION_));
}
irReceiver = new IRrecv(irPin, kCaptureBufferSize, P016_TIMEOUT, true);
irReceiver = new (std::nothrow) IRrecv(irPin, kCaptureBufferSize, P016_TIMEOUT, true);
# ifdef PLUGIN_016_DEBUG
addLog(LOG_LEVEL_INFO, F("P016_PLUGIN_INIT IR receiver created"));
# endif // PLUGIN_016_DEBUG
+24 -6
View File
@@ -99,21 +99,23 @@ boolean Plugin_035(uint8_t function, struct EventStruct *event, String &command)
case PLUGIN_INIT:
{
int irPin = CONFIG_PIN1;
if (Plugin_035_irSender == 0 && validGpio(irPin))
if (Plugin_035_irSender == nullptr && validGpio(irPin))
{
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
addLog(LOG_LEVEL_INFO, F("INIT: IR TX"));
addLog(LOG_LEVEL_INFO, F("IR lib Version: " _IRREMOTEESP8266_VERSION_));
addLog(LOG_LEVEL_INFO, String(F("Supported Protocols by IRSEND: ")) + listProtocols());
}
Plugin_035_irSender = new IRsend(irPin);
Plugin_035_irSender->begin(); // Start the sender
Plugin_035_irSender = new (std::nothrow) IRsend(irPin);
if (Plugin_035_irSender != nullptr) {
Plugin_035_irSender->begin(); // Start the sender
}
}
if (Plugin_035_irSender != 0 && irPin == -1)
if (Plugin_035_irSender != nullptr && irPin == -1)
{
addLog(LOG_LEVEL_INFO, F("INIT: IR TX Removed"));
delete Plugin_035_irSender;
Plugin_035_irSender = 0;
Plugin_035_irSender = nullptr;
}
#ifdef P016_P035_Extended_AC
@@ -129,7 +131,7 @@ boolean Plugin_035(uint8_t function, struct EventStruct *event, String &command)
{
addLog(LOG_LEVEL_INFO, F("INIT AC: IR TX Removed"));
delete Plugin_035_commonAc;
Plugin_035_commonAc = 0;
Plugin_035_commonAc = nullptr;
}
#endif
@@ -137,6 +139,22 @@ boolean Plugin_035(uint8_t function, struct EventStruct *event, String &command)
break;
}
case PLUGIN_EXIT:
{
if (Plugin_035_irSender != nullptr) {
delete Plugin_035_irSender;
Plugin_035_irSender = nullptr;
}
#ifdef P016_P035_Extended_AC
if (Plugin_035_commonAc != nullptr) {
delete Plugin_035_commonAc;
Plugin_035_commonAc = nullptr;
}
#endif
success = true;
break;
}
case PLUGIN_WRITE:
{
String cmdCode = parseString(command,1);
+19 -6
View File
@@ -31,7 +31,7 @@
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel *Plugin_038_pixels;
Adafruit_NeoPixel *Plugin_038_pixels = nullptr;
#define PLUGIN_038
#define PLUGIN_ID_038 38
@@ -94,23 +94,36 @@ boolean Plugin_038(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_INIT:
{
if (!Plugin_038_pixels)
if (Plugin_038_pixels == nullptr)
{
uint8_t striptype = PCONFIG(1);
if (striptype == 1)
Plugin_038_pixels = new Adafruit_NeoPixel(PCONFIG(0), CONFIG_PIN1, NEO_GRB + NEO_KHZ800);
Plugin_038_pixels = new (std::nothrow) Adafruit_NeoPixel(PCONFIG(0), CONFIG_PIN1, NEO_GRB + NEO_KHZ800);
else if (striptype == 2)
Plugin_038_pixels = new Adafruit_NeoPixel(PCONFIG(0), CONFIG_PIN1, NEO_GRBW + NEO_KHZ800);
Plugin_038_pixels = new (std::nothrow) Adafruit_NeoPixel(PCONFIG(0), CONFIG_PIN1, NEO_GRBW + NEO_KHZ800);
else
Plugin_038_pixels = new Adafruit_NeoPixel(PCONFIG(0), CONFIG_PIN1, NEO_GRB + NEO_KHZ800);
Plugin_038_pixels = new (std::nothrow) Adafruit_NeoPixel(PCONFIG(0), CONFIG_PIN1, NEO_GRB + NEO_KHZ800);
Plugin_038_pixels->begin(); // This initializes the NeoPixel library.
if (Plugin_038_pixels != nullptr) {
Plugin_038_pixels->begin(); // This initializes the NeoPixel library.
}
}
MaxPixels = PCONFIG(0);
success = Plugin_038_pixels != nullptr;
break;
}
case PLUGIN_EXIT:
{
if (Plugin_038_pixels != nullptr) {
delete Plugin_038_pixels;
Plugin_038_pixels = nullptr;
}
success = true;
break;
}
case PLUGIN_WRITE:
{
if (Plugin_038_pixels)
+15 -4
View File
@@ -80,15 +80,26 @@ boolean Plugin_041(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_INIT:
{
if (!Plugin_041_pixels)
if (Plugin_041_pixels == nullptr)
{
Plugin_041_pixels = new Adafruit_NeoPixel(NUM_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800);
Plugin_041_pixels->begin(); // This initializes the NeoPixel library.
Plugin_041_pixels = new (std::nothrow) Adafruit_NeoPixel(NUM_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800);
if (Plugin_041_pixels != nullptr) {
Plugin_041_pixels->begin(); // This initializes the NeoPixel library.
}
}
Plugin_041_red = PCONFIG(0);
Plugin_041_green = PCONFIG(1);
Plugin_041_blue = PCONFIG(2);
success = true;
success = Plugin_041_pixels != nullptr;
break;
}
case PLUGIN_EXIT:
{
if (Plugin_041_pixels != nullptr) {
delete Plugin_041_pixels;
Plugin_041_pixels = nullptr;
}
break;
}
+16 -5
View File
@@ -273,10 +273,12 @@ boolean Plugin_042(uint8_t function, struct EventStruct *event, String& string)
if (Candle_pixels) {
delete Candle_pixels;
}
Candle_pixels = new Adafruit_NeoPixel(NUM_PIXEL, CONFIG_PIN1, NEO_GRB + NEO_KHZ800);
SetPixelsBlack();
Candle_pixels->setBrightness(Candle_bright);
Candle_pixels->begin();
Candle_pixels = new (std::nothrow) Adafruit_NeoPixel(NUM_PIXEL, CONFIG_PIN1, NEO_GRB + NEO_KHZ800);
if (Candle_pixels != nullptr) {
SetPixelsBlack();
Candle_pixels->setBrightness(Candle_bright);
Candle_pixels->begin();
}
#ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
@@ -287,7 +289,16 @@ boolean Plugin_042(uint8_t function, struct EventStruct *event, String& string)
#endif
}
success = true;
success = Candle_pixels != nullptr;
break;
}
case PLUGIN_EXIT:
{
if (Candle_pixels != nullptr) {
delete Candle_pixels;
Candle_pixels = nullptr;
}
break;
}
+1 -1
View File
@@ -279,7 +279,7 @@ boolean Plugin_046(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_INIT:
{
if (!P046_data) {
P046_data = new P046_data_struct();
P046_data = new (std::nothrow) P046_data_struct();
}
uint8_t choice = PCONFIG(0);
+5 -3
View File
@@ -127,10 +127,12 @@ boolean Plugin_054(uint8_t function, struct EventStruct *event, String& string)
if (Plugin_054_DMXBuffer) {
delete [] Plugin_054_DMXBuffer;
}
Plugin_054_DMXBuffer = new uint8_t[Plugin_054_DMXSize];
memset(Plugin_054_DMXBuffer, 0, Plugin_054_DMXSize);
Plugin_054_DMXBuffer = new (std::nothrow) uint8_t[Plugin_054_DMXSize];
if (Plugin_054_DMXBuffer != nullptr) {
memset(Plugin_054_DMXBuffer, 0, Plugin_054_DMXSize);
}
success = true;
success = Plugin_054_DMXBuffer != nullptr;
break;
}
+40 -44
View File
@@ -62,35 +62,20 @@
class CPlugin_055_Data
{
public:
long millisStateEnd;
long millisChimeTime;
long millisPauseTime;
long millisStateEnd = 0;
long millisChimeTime = 60;
long millisPauseTime = 400;
int pin[4];
uint8_t lowActive;
uint8_t chimeClock;
int pin[4] = {0};
uint8_t lowActive = false;
uint8_t chimeClock = true;
char FIFO[PLUGIN_055_FIFO_SIZE];
uint8_t FIFO_IndexR;
uint8_t FIFO_IndexW;
void Plugin_055_Data()
{
millisStateEnd = 0;
millisChimeTime = 60;
millisPauseTime = 400;
for (uint8_t i=0; i<4; i++)
pin[i] = -1;
lowActive = false;
chimeClock = true;
FIFO_IndexR = 0;
FIFO_IndexW = 0;
}
char FIFO[PLUGIN_055_FIFO_SIZE] = {0};
uint8_t FIFO_IndexR = 0;
uint8_t FIFO_IndexW = 0;
};
static CPlugin_055_Data* Plugin_055_Data = NULL;
static CPlugin_055_Data* Plugin_055_Data = nullptr;
boolean Plugin_055(uint8_t function, struct EventStruct *event, String& string)
@@ -188,31 +173,42 @@ boolean Plugin_055(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_INIT:
{
if (!Plugin_055_Data)
Plugin_055_Data = new CPlugin_055_Data();
Plugin_055_Data = new (std::nothrow) CPlugin_055_Data();
Plugin_055_Data->lowActive = Settings.TaskDevicePin1Inversed[event->TaskIndex];
Plugin_055_Data->millisChimeTime = PCONFIG(0);
Plugin_055_Data->millisPauseTime = PCONFIG(1);
Plugin_055_Data->chimeClock = PCONFIG(2);
if (Plugin_055_Data != nullptr) {
Plugin_055_Data->lowActive = Settings.TaskDevicePin1Inversed[event->TaskIndex];
Plugin_055_Data->millisChimeTime = PCONFIG(0);
Plugin_055_Data->millisPauseTime = PCONFIG(1);
Plugin_055_Data->chimeClock = PCONFIG(2);
String log = F("Chime: GPIO: ");
for (uint8_t i=0; i<4; i++)
{
int pin = Settings.TaskDevicePin[i][event->TaskIndex];
Plugin_055_Data->pin[i] = pin;
if (pin >= 0)
String log = F("Chime: GPIO: ");
for (uint8_t i=0; i<4; i++)
{
pinMode(pin, OUTPUT);
digitalWrite(pin, Plugin_055_Data->lowActive);
int pin = Settings.TaskDevicePin[i][event->TaskIndex];
Plugin_055_Data->pin[i] = pin;
if (pin >= 0)
{
pinMode(pin, OUTPUT);
digitalWrite(pin, Plugin_055_Data->lowActive);
}
log += pin;
log += ' ';
}
log += pin;
log += ' ';
if (Plugin_055_Data->lowActive)
log += F("!");
addLog(LOG_LEVEL_INFO, log);
success = true;
}
if (Plugin_055_Data->lowActive)
log += F("!");
addLog(LOG_LEVEL_INFO, log);
success = true;
break;
}
case PLUGIN_EXIT:
{
if (Plugin_055_Data != nullptr) {
delete Plugin_055_Data;
Plugin_055_Data = nullptr;
}
break;
}
+5 -3
View File
@@ -22,7 +22,7 @@
#include "ESPEasy-Globals.h"
CjkSDS011 *Plugin_056_SDS = NULL;
CjkSDS011 *Plugin_056_SDS = nullptr;
boolean Plugin_056(uint8_t function, struct EventStruct *event, String& string)
@@ -105,12 +105,13 @@ boolean Plugin_056(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_INIT:
{
if (Plugin_056_SDS)
if (Plugin_056_SDS) {
delete Plugin_056_SDS;
}
const int16_t serial_rx = CONFIG_PIN1;
const int16_t serial_tx = CONFIG_PIN2;
const ESPEasySerialPort port = static_cast<ESPEasySerialPort>(CONFIG_PORT);
Plugin_056_SDS = new CjkSDS011(port, serial_rx, serial_tx);
Plugin_056_SDS = new (std::nothrow) CjkSDS011(port, serial_rx, serial_tx);
String log = F("SDS : Init OK ESP GPIO-pin RX:");
log += serial_rx;
log += F(" TX:");
@@ -124,6 +125,7 @@ boolean Plugin_056(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_EXIT:
{
// //FIXME: if this plugin is used more than once at the same time, things go horribly wrong :)
// FIXME TD-er: Must implement plugin_data_struct for this
//
// if (Plugin_056_SDS)
// delete Plugin_056_SDS;
+3 -1
View File
@@ -210,6 +210,7 @@ boolean Plugin_062(uint8_t function, struct EventStruct *event, String& string)
SaveCustomTaskSettings(event->TaskIndex, reinterpret_cast<const uint8_t *>(&(P062_data->StoredSettings)), sizeof(P062_data->StoredSettings));
if (!canCalibrate) {
delete P062_data;
P062_data = nullptr;
} else {
bool clearCalibration = isFormItemChecked(F("p062_clear_calibrate"));
if (clearCalibration) {
@@ -232,11 +233,12 @@ boolean Plugin_062(uint8_t function, struct EventStruct *event, String& string)
P062_data_struct *P062_data = static_cast<P062_data_struct *>(getPluginTaskData(event->TaskIndex));
if (nullptr != P062_data) {
success = true;
if (!P062_data->init(event->TaskIndex, PCONFIG(0), PCONFIG(1), tbUseCalibration)) {
clearPluginTaskData(event->TaskIndex);
P062_data = nullptr;
} else {
success = true;
uint8_t touch_treshold = PCONFIG(2);
if(touch_treshold == 0) {
touch_treshold = P062_DEFAULT_TOUCH_TRESHOLD; //default value
+9
View File
@@ -121,6 +121,15 @@ boolean Plugin_065(uint8_t function, struct EventStruct *event, String& string)
break;
}
case PLUGIN_EXIT:
{
if (P065_easySerial != nullptr) {
delete P065_easySerial;
P065_easySerial = nullptr;
}
break;
}
case PLUGIN_WRITE:
{
if (!P065_easySerial) {
+2 -2
View File
@@ -217,7 +217,6 @@ boolean Plugin_078(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_INIT:
{
Plugin_078_init = true;
if (Plugin_078_SoftSerial != NULL) {
delete Plugin_078_SoftSerial;
Plugin_078_SoftSerial=NULL;
@@ -233,9 +232,10 @@ boolean Plugin_078(uint8_t function, struct EventStruct *event, String& string)
delete Plugin_078_SDM;
Plugin_078_SDM=NULL;
}
Plugin_078_SDM = new SDM(*Plugin_078_SoftSerial, baudrate, P078_DEPIN);
Plugin_078_SDM = new (std::nothrow) SDM(*Plugin_078_SoftSerial, baudrate, P078_DEPIN);
if (Plugin_078_SDM != nullptr) {
Plugin_078_SDM->begin();
Plugin_078_init = true;
success = true;
}
break;
+2 -1
View File
@@ -207,9 +207,10 @@ boolean Plugin_088(uint8_t function, struct EventStruct *event, String& string)
{
addLog(LOG_LEVEL_INFO, F("P088: Heatpump IR transmitter deactivated"));
if (Plugin_088_irSender != NULL)
if (Plugin_088_irSender != nullptr)
{
delete Plugin_088_irSender;
Plugin_088_irSender = nullptr;
}
break;
+21 -6
View File
@@ -261,16 +261,31 @@ boolean Plugin_095(uint8_t function, struct EventStruct *event, String& string)
TFT_Settings.address_tft_dc = PIN(1);
TFT_Settings.address_tft_rst = PIN(2);
TFT_Settings.rotation = PCONFIG(1);
if (tft != nullptr) {
delete tft;
tft = nullptr;
}
tft = new Adafruit_ILI9341(TFT_Settings.address_tft_cs, TFT_Settings.address_tft_dc, TFT_Settings.address_tft_rst);
tft->begin();
tft->setRotation(TFT_Settings.rotation);
tft->fillScreen(ILI9341_WHITE);
Plugin_095_printText("ESPEasy", 1, 1);
success = true;
tft = new (std::nothrow) Adafruit_ILI9341(TFT_Settings.address_tft_cs, TFT_Settings.address_tft_dc, TFT_Settings.address_tft_rst);
if (tft != nullptr) {
tft->begin();
tft->setRotation(TFT_Settings.rotation);
tft->fillScreen(ILI9341_WHITE);
Plugin_095_printText("ESPEasy", 1, 1);
success = true;
}
break;
}
case PLUGIN_EXIT:
{
if (tft != nullptr) {
delete tft;
tft = nullptr;
}
break;
}
case PLUGIN_WRITE:
{
String tmpString = String(string);
+29 -13
View File
@@ -285,20 +285,36 @@ boolean Plugin_096(uint8_t function, struct EventStruct *event, String& string)
EPD_Settings.width = PCONFIG(2);
EPD_Settings.height = PCONFIG(3);
eInkScreen = new LOLIN_IL3897(EPD_Settings.width, EPD_Settings.height, EPD_Settings.address_epd_dc, EPD_Settings.address_epd_rst, EPD_Settings.address_epd_cs, EPD_Settings.address_epd_busy); //hardware SPI
plugin_096_sequence_in_progress = false;
eInkScreen->begin();
eInkScreen->clearBuffer();
if (eInkScreen != nullptr) {
delete eInkScreen;
eInkScreen = nullptr;
}
eInkScreen->setTextColor(EPD_BLACK);
eInkScreen->setTextSize(3);
eInkScreen->println("ESP Easy");
eInkScreen->setTextSize(2);
eInkScreen->println("eInk shield");
eInkScreen->display();
delay(100);
success = true;
eInkScreen = new (std::nothrow) LOLIN_IL3897(EPD_Settings.width, EPD_Settings.height, EPD_Settings.address_epd_dc, EPD_Settings.address_epd_rst, EPD_Settings.address_epd_cs, EPD_Settings.address_epd_busy); //hardware SPI
if (eInkScreen != nullptr) {
plugin_096_sequence_in_progress = false;
eInkScreen->begin();
eInkScreen->clearBuffer();
eInkScreen->setTextColor(EPD_BLACK);
eInkScreen->setTextSize(3);
eInkScreen->println("ESP Easy");
eInkScreen->setTextSize(2);
eInkScreen->println("eInk shield");
eInkScreen->display();
delay(100);
success = true;
}
break;
}
case PLUGIN_EXIT:
{
if (eInkScreen != nullptr) {
delete eInkScreen;
eInkScreen = nullptr;
}
break;
}
+1 -1
View File
@@ -232,7 +232,7 @@ boolean Plugin_102(uint8_t function, struct EventStruct *event, String& string)
}
// Hardware serial is RX on 3 and TX on 1
P102_PZEM_sensor = new PZEM004Tv30(port, rxPin, txPin);
P102_PZEM_sensor = new (std::nothrow) PZEM004Tv30(port, rxPin, txPin);
// Sequence for changing PZEM address
if (P102_PZEM_ADDR_SET == 1) // if address programming confirmed
+2 -2
View File
@@ -279,9 +279,9 @@ boolean Plugin_109(byte function, struct EventStruct *event, String& string)
uint8_t OLED_address = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
if (Settings.TaskDevicePluginConfig[event->TaskIndex][2] == 1) {
P109_display = new SSD1306Wire(OLED_address, Settings.Pin_i2c_sda, Settings.Pin_i2c_scl);
P109_display = new (std::nothrow) SSD1306Wire(OLED_address, Settings.Pin_i2c_sda, Settings.Pin_i2c_scl);
} else {
P109_display = new SH1106Wire(OLED_address, Settings.Pin_i2c_sda, Settings.Pin_i2c_scl);
P109_display = new (std::nothrow) SH1106Wire(OLED_address, Settings.Pin_i2c_sda, Settings.Pin_i2c_scl);
}
P109_display->init(); // call to local override of init function
P109_display->displayOn();
+14 -1
View File
@@ -8,13 +8,26 @@
Modbus::Modbus() : ModbusClient(nullptr), errcnt(0), timeout(0),
TXRXstate(MODBUS_IDLE), RXavailable(0), payLoad(0) {}
Modbus::~Modbus() {
if (ModbusClient) {
ModbusClient->flush();
ModbusClient->stop();
delete (ModbusClient);
delay(1);
ModbusClient = nullptr;
}
}
bool Modbus::begin(uint8_t function, uint8_t ModbusID, uint16_t ModbusRegister, MODBUS_registerTypes_t type, char *IPaddress)
{
currentRegister = ModbusRegister;
currentFunction = function;
incomingValue = type;
resultReceived = false;
ModbusClient = new WiFiClient();
ModbusClient = new (std::nothrow) WiFiClient();
if (ModbusClient == nullptr) {
return false;
}
ModbusClient->setNoDelay(true);
ModbusClient->setTimeout(CONTROLLER_CLIENTTIMEOUT_DFLT);
timeout = millis();
+1
View File
@@ -14,6 +14,7 @@ class Modbus {
public:
Modbus(void);
~Modbus();
bool handle();
bool begin(uint8_t function,
uint8_t ModbusID,
+7 -3
View File
@@ -627,13 +627,17 @@ static const IPAddress SSDP_MULTICAST_ADDR(239, 255, 255, 250);
bool SSDP_begin() {
_pending = false;
if (_server) {
if (_server != nullptr) {
_server->unref();
// FIXME TD-er: Shouldn't this also call delete _server ?
_server = 0;
_server = nullptr;
}
_server = new UdpContext;
_server = new (std::nothrow) UdpContext;
if (_server == nullptr) {
return false;
}
_server->ref();
ip_addr_t ifaddr;
@@ -20,6 +20,7 @@ P020_Task::P020_Task(taskIndex_t taskIndex) : _taskIndex(taskIndex) {
P020_Task::~P020_Task() {
stopServer();
serialEnd();
}
bool P020_Task::serverActive(WiFiServer *server) {
@@ -19,6 +19,7 @@ P044_Task::P044_Task() {
P044_Task::~P044_Task() {
stopServer();
serialEnd();
}
bool P044_Task::serverActive(WiFiServer *server) {
+8 -1
View File
@@ -14,6 +14,13 @@ P062_data_struct::P062_data_struct() {
clearCalibrationData(); // Reset
}
P062_data_struct::~P062_data_struct() {
if (keypad != nullptr) {
delete keypad;
keypad = nullptr;
}
}
bool P062_data_struct::init(taskIndex_t taskIndex,
uint8_t i2c_addr,
bool scancode,
@@ -26,7 +33,7 @@ bool P062_data_struct::init(taskIndex_t taskIndex,
_keepCalibrationData = keepCalibrationData;
if (!keypad) {
keypad = new Adafruit_MPR121();
keypad = new (std::nothrow) Adafruit_MPR121();
}
if (keypad) {
keypad->begin(_i2c_addr);
+1
View File
@@ -14,6 +14,7 @@ struct P062_data_struct : public PluginTaskData_base {
public:
P062_data_struct();
~P062_data_struct();
bool init(taskIndex_t taskIndex,
uint8_t i2c_addr,
bool scancode,
+1 -1
View File
@@ -51,7 +51,7 @@ bool P082_data_struct::init(ESPEasySerialPort port, const int16_t serial_rx, con
return false;
}
reset();
gps = new (std::nothrow) TinyGPSPlus();
gps = new (std::nothrow) TinyGPSPlus();
easySerial = new (std::nothrow) ESPeasySerial(port, serial_rx, serial_tx);
if (easySerial != nullptr) {
+13 -2
View File
@@ -11,9 +11,20 @@
P111_data_struct::P111_data_struct(uint8_t csPin, uint8_t rstPin) : mfrc522(nullptr), _csPin(csPin), _rstPin(rstPin)
{}
P111_data_struct::~P111_data_struct() {
if (mfrc522 != nullptr) {
delete mfrc522;
mfrc522 = nullptr;
}
}
void P111_data_struct::init() {
if (mfrc522 == nullptr){
mfrc522 = new MFRC522 (_csPin, _rstPin); // Instantiate a MFRC522
if (mfrc522 != nullptr) {
delete mfrc522;
mfrc522 = nullptr;
}
mfrc522 = new (std::nothrow) MFRC522(_csPin, _rstPin); // Instantiate a MFRC522
if (mfrc522 != nullptr) {
mfrc522->PCD_Init(); // Initialize MFRC522 reader
}
}
+2 -1
View File
@@ -9,11 +9,12 @@
struct P111_data_struct : public PluginTaskData_base {
P111_data_struct(uint8_t csPin, uint8_t rstPin);
~P111_data_struct();
void init();
uint8_t readCardStatus(unsigned long *key, bool *removedTag);
String getCardName();
MFRC522 *mfrc522;
MFRC522 *mfrc522 = nullptr;
uint8_t counter = 0;