From 929e74d3263833da2c7d2d65c7ed6e6c66f5c32f Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 18 Oct 2023 15:56:54 +0100 Subject: [PATCH] nulls after deletes General cleanup by having consistent approach to setting null after deleting a reference. --- lib/TNFSlib/tnfslibMountInfo.cpp | 3 +++ lib/bus/s100spi/s100spi.h | 4 ++++ lib/device/adamnet/disk.cpp | 3 +++ lib/device/adamnet/keyboard.cpp | 1 + lib/device/adamnet/modem.cpp | 1 + lib/device/adamnet/network.cpp | 3 +++ lib/device/adamnet/printer.cpp | 8 +++++++- lib/device/comlynx/disk.cpp | 3 +++ lib/device/comlynx/keyboard.cpp | 1 + lib/device/comlynx/modem.cpp | 1 + lib/device/comlynx/network.cpp | 8 ++++++++ lib/device/comlynx/printer.cpp | 8 +++++++- lib/device/cx16_i2c/disk.cpp | 3 +++ lib/device/cx16_i2c/modem.cpp | 1 + lib/device/cx16_i2c/modem.h | 2 +- lib/device/cx16_i2c/printer.cpp | 11 +++++++++-- lib/device/drivewire/modem.cpp | 1 + lib/device/drivewire/network.cpp | 11 +++++++++++ lib/device/drivewire/printer.cpp | 11 +++++++++-- lib/device/h89/modem.cpp | 1 + lib/device/h89/network.cpp | 8 ++++++++ lib/device/h89/printer.cpp | 6 +++++- lib/device/iec/modem.cpp | 1 + lib/device/iec/network.cpp | 5 +++++ lib/device/iec/printer.cpp | 6 +++++- lib/device/iwm/modem.cpp | 1 + lib/device/iwm/network.cpp | 8 ++++++++ lib/device/iwm/printer.cpp | 6 +++++- lib/device/mac/modem.cpp | 2 ++ lib/device/mac/printer.cpp | 6 +++++- lib/device/new/disk.cpp | 3 +++ lib/device/new/keyboard.cpp | 1 + lib/device/new/modem.cpp | 1 + lib/device/new/network.cpp | 8 ++++++++ lib/device/new/printer.cpp | 6 +++++- lib/device/new/serial.cpp | 1 + lib/device/rc2014/disk.cpp | 3 +++ lib/device/rc2014/modem.cpp | 1 + lib/device/rc2014/network.cpp | 8 ++++++++ lib/device/rc2014/printer.cpp | 6 +++++- lib/device/rs232/disk.cpp | 3 +++ lib/device/rs232/modem.cpp | 9 ++++++++- lib/device/rs232/network.cpp | 8 ++++++++ lib/device/rs232/printer.cpp | 6 +++++- lib/device/s100spi/disk.cpp | 3 +++ lib/device/s100spi/modem.cpp | 1 + lib/device/s100spi/network.cpp | 8 ++++++++ lib/device/s100spi/printer.cpp | 6 +++++- lib/device/s100spi/printer.h | 2 +- lib/device/sio/disk.cpp | 3 +++ lib/device/sio/network.cpp | 12 ++++++++++++ lib/device/sio/printer.cpp | 6 +++++- lib/ftp/fnFTP.cpp | 3 +++ lib/fuji/fujiHost.cpp | 1 + lib/media/atari/diskTypeAtx.cpp | 3 +++ lib/modem/modem.cpp | 1 + lib/network-protocol/FS.cpp | 1 + lib/network-protocol/FTP.cpp | 1 + lib/network-protocol/HTTP.cpp | 2 ++ lib/network-protocol/TCP.cpp | 1 - lib/utils/cbuf.cpp | 1 + platformio-sample.ini | 2 +- 62 files changed, 235 insertions(+), 20 deletions(-) diff --git a/lib/TNFSlib/tnfslibMountInfo.cpp b/lib/TNFSlib/tnfslibMountInfo.cpp index d6e92d3c7..34a6c2468 100644 --- a/lib/TNFSlib/tnfslibMountInfo.cpp +++ b/lib/TNFSlib/tnfslibMountInfo.cpp @@ -21,7 +21,10 @@ tnfsMountInfo::~tnfsMountInfo() for (int i = 0; i < TNFS_MAX_FILE_HANDLES; i++) { if (_file_handles[i] != nullptr) + { delete _file_handles[i]; + _file_handles[i] = nullptr; + } } // Delete any remaining directory cache entries empty_dircache(); diff --git a/lib/bus/s100spi/s100spi.h b/lib/bus/s100spi/s100spi.h index 3be22cfe7..993935266 100644 --- a/lib/bus/s100spi/s100spi.h +++ b/lib/bus/s100spi/s100spi.h @@ -229,6 +229,10 @@ class systemBus virtualDevice *deviceById(uint8_t device_id); void changeDeviceId(virtualDevice *pDevice, uint8_t device_id); QueueHandle_t qs100spiMessages = nullptr; + + bool shuttingDown = false; + bool getShuttingDown() { return shuttingDown; }; + }; extern systemBus s100Bus; diff --git a/lib/device/adamnet/disk.cpp b/lib/device/adamnet/disk.cpp index eb0b5b40c..638074093 100755 --- a/lib/device/adamnet/disk.cpp +++ b/lib/device/adamnet/disk.cpp @@ -23,7 +23,10 @@ adamDisk::adamDisk() adamDisk::~adamDisk() { if (_media != nullptr) + { delete _media; + _media = nullptr; + } } void adamDisk::reset() diff --git a/lib/device/adamnet/keyboard.cpp b/lib/device/adamnet/keyboard.cpp index 6a32a7d89..429f2f6cc 100644 --- a/lib/device/adamnet/keyboard.cpp +++ b/lib/device/adamnet/keyboard.cpp @@ -19,6 +19,7 @@ adamKeyboard::~adamKeyboard() // vTaskDelete(kbTask); server->stop(); delete server; + server = nullptr; } void adamKeyboard::adamnet_control_status() diff --git a/lib/device/adamnet/modem.cpp b/lib/device/adamnet/modem.cpp index 080462e79..c8fb4e198 100755 --- a/lib/device/adamnet/modem.cpp +++ b/lib/device/adamnet/modem.cpp @@ -87,6 +87,7 @@ adamModem::~adamModem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } if (telnet != nullptr) diff --git a/lib/device/adamnet/network.cpp b/lib/device/adamnet/network.cpp index d08a34d63..110101a77 100755 --- a/lib/device/adamnet/network.cpp +++ b/lib/device/adamnet/network.cpp @@ -61,6 +61,9 @@ adamNetwork::~adamNetwork() delete receiveBuffer; delete transmitBuffer; delete specialBuffer; + receiveBuffer = nullptr; + transmitBuffer = nullptr; + specialBuffer = nullptr; if (protocol != nullptr) delete protocol; diff --git a/lib/device/adamnet/printer.cpp b/lib/device/adamnet/printer.cpp index df57f98d0..b81a48b62 100755 --- a/lib/device/adamnet/printer.cpp +++ b/lib/device/adamnet/printer.cpp @@ -72,7 +72,10 @@ adamPrinter::~adamPrinter() vTaskDelete(thPrinter); if (_pptr != nullptr) + { delete _pptr; + _pptr = nullptr; + } vQueueDelete(pxq); } @@ -147,7 +150,10 @@ void adamPrinter::shutdown() void adamPrinter::set_printer_type(printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/device/comlynx/disk.cpp b/lib/device/comlynx/disk.cpp index 0da15cc14..c0da7d43a 100755 --- a/lib/device/comlynx/disk.cpp +++ b/lib/device/comlynx/disk.cpp @@ -23,7 +23,10 @@ lynxDisk::lynxDisk() lynxDisk::~lynxDisk() { if (_media != nullptr) + { delete _media; + _media = nullptr; + } } void lynxDisk::reset() diff --git a/lib/device/comlynx/keyboard.cpp b/lib/device/comlynx/keyboard.cpp index 8a35e784c..2d4091509 100644 --- a/lib/device/comlynx/keyboard.cpp +++ b/lib/device/comlynx/keyboard.cpp @@ -19,6 +19,7 @@ lynxKeyboard::~lynxKeyboard() // vTaskDelete(kbTask); server->stop(); delete server; + server = nullptr; } void lynxKeyboard::comlynx_control_status() diff --git a/lib/device/comlynx/modem.cpp b/lib/device/comlynx/modem.cpp index 6f6d0653c..ee4e29daa 100755 --- a/lib/device/comlynx/modem.cpp +++ b/lib/device/comlynx/modem.cpp @@ -87,6 +87,7 @@ lynxModem::~lynxModem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } if (telnet != nullptr) diff --git a/lib/device/comlynx/network.cpp b/lib/device/comlynx/network.cpp index acb65d816..b3418baa4 100755 --- a/lib/device/comlynx/network.cpp +++ b/lib/device/comlynx/network.cpp @@ -60,6 +60,14 @@ lynxNetwork::~lynxNetwork() delete receiveBuffer; delete transmitBuffer; delete specialBuffer; + receiveBuffer = nullptr; + transmitBuffer = nullptr; + specialBuffer = nullptr; + + if (protocol != nullptr) + delete protocol; + + protocol = nullptr; } /** LYNX COMMANDS ***************************************************************/ diff --git a/lib/device/comlynx/printer.cpp b/lib/device/comlynx/printer.cpp index 81d7a2ccc..b34744629 100755 --- a/lib/device/comlynx/printer.cpp +++ b/lib/device/comlynx/printer.cpp @@ -70,7 +70,10 @@ lynxPrinter::~lynxPrinter() vTaskDelete(thPrinter); if (_pptr != nullptr) + { delete _pptr; + _pptr = nullptr; + } } void lynxPrinter::start_printer_task() @@ -150,7 +153,10 @@ void lynxPrinter::shutdown() void lynxPrinter::set_printer_type(printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/device/cx16_i2c/disk.cpp b/lib/device/cx16_i2c/disk.cpp index 48a24e7f7..a78961a8b 100644 --- a/lib/device/cx16_i2c/disk.cpp +++ b/lib/device/cx16_i2c/disk.cpp @@ -88,7 +88,10 @@ mediatype_t cx16Disk::mount(FILE *f, const char *filename, uint32_t disksize, me cx16Disk::~cx16Disk() { if (_disk != nullptr) + { delete _disk; + _disk = nullptr; + } } // Unmount disk file diff --git a/lib/device/cx16_i2c/modem.cpp b/lib/device/cx16_i2c/modem.cpp index 4019d1759..444e94e43 100644 --- a/lib/device/cx16_i2c/modem.cpp +++ b/lib/device/cx16_i2c/modem.cpp @@ -11,6 +11,7 @@ cx16Modem::cx16Modem(FileSystem *_fs, bool snifferEnable) cx16Modem::~cx16Modem() { delete modemSniffer; + modemSniffer = nullptr; } #endif /* BUILD_CX16 */ diff --git a/lib/device/cx16_i2c/modem.h b/lib/device/cx16_i2c/modem.h index c58d38a6a..b7034b1ad 100644 --- a/lib/device/cx16_i2c/modem.h +++ b/lib/device/cx16_i2c/modem.h @@ -10,8 +10,8 @@ class cx16Modem : public virtualDevice { private: - ModemSniffer* modemSniffer; FileSystem *activeFS; + ModemSniffer* modemSniffer; time_t _lasttime = 0; public: diff --git a/lib/device/cx16_i2c/printer.cpp b/lib/device/cx16_i2c/printer.cpp index 909142f1a..7642354e0 100644 --- a/lib/device/cx16_i2c/printer.cpp +++ b/lib/device/cx16_i2c/printer.cpp @@ -35,7 +35,11 @@ constexpr const char * const cx16Printer::printer_model_str[PRINTER_INVALID]; cx16Printer::~cx16Printer() { - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + _pptr = nullptr; + } } // write for W commands @@ -158,7 +162,10 @@ void cx16Printer::status() void cx16Printer::set_printer_type(cx16Printer::printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/device/drivewire/modem.cpp b/lib/device/drivewire/modem.cpp index fc5094132..a2a819ab1 100644 --- a/lib/device/drivewire/modem.cpp +++ b/lib/device/drivewire/modem.cpp @@ -95,6 +95,7 @@ drivewireModem::~drivewireModem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } if (telnet != nullptr) diff --git a/lib/device/drivewire/network.cpp b/lib/device/drivewire/network.cpp index b3d81e07a..2fb9f4d79 100755 --- a/lib/device/drivewire/network.cpp +++ b/lib/device/drivewire/network.cpp @@ -54,6 +54,14 @@ drivewireNetwork::~drivewireNetwork() delete receiveBuffer; delete transmitBuffer; delete specialBuffer; + receiveBuffer = nullptr; + transmitBuffer = nullptr; + specialBuffer = nullptr; + + if (protocol != nullptr) + delete protocol; + + protocol = nullptr; } /** DRIVEWIRE COMMANDS ***************************************************************/ @@ -403,7 +411,10 @@ bool drivewireNetwork::parseURL() string unit = deviceSpec.substr(0, deviceSpec.find_first_of(":") + 1); if (urlParser != nullptr) + { delete urlParser; + urlParser = nullptr; + } // Prepend prefix, if set. if (prefix.length() > 0) diff --git a/lib/device/drivewire/printer.cpp b/lib/device/drivewire/printer.cpp index 25aac483a..a469f6925 100755 --- a/lib/device/drivewire/printer.cpp +++ b/lib/device/drivewire/printer.cpp @@ -31,7 +31,11 @@ constexpr const char * const drivewirePrinter::printer_model_str[PRINTER_INVALID drivewirePrinter::~drivewirePrinter() { - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + _pptr = nullptr; + } } // write for W commands @@ -57,7 +61,10 @@ void drivewirePrinter::drivewire_status() void drivewirePrinter::set_printer_type(drivewirePrinter::printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/device/h89/modem.cpp b/lib/device/h89/modem.cpp index dd0a0712f..fdd0a7e5d 100644 --- a/lib/device/h89/modem.cpp +++ b/lib/device/h89/modem.cpp @@ -95,6 +95,7 @@ H89Modem::~H89Modem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } if (telnet != nullptr) diff --git a/lib/device/h89/network.cpp b/lib/device/h89/network.cpp index 14bec7e0f..ad5778dce 100644 --- a/lib/device/h89/network.cpp +++ b/lib/device/h89/network.cpp @@ -54,6 +54,14 @@ H89Network::~H89Network() delete receiveBuffer; delete transmitBuffer; delete specialBuffer; + receiveBuffer = nullptr; + transmitBuffer = nullptr; + specialBuffer = nullptr; + + if (protocol != nullptr) + delete protocol; + + protocol = nullptr; } /** H89 COMMANDS ***************************************************************/ diff --git a/lib/device/h89/printer.cpp b/lib/device/h89/printer.cpp index 170aa844b..6da78ffea 100644 --- a/lib/device/h89/printer.cpp +++ b/lib/device/h89/printer.cpp @@ -42,6 +42,7 @@ H89Printer::~H89Printer() { //vTaskDelete(thPrinter); delete _pptr; + _pptr = nullptr; } H89Printer::printer_type H89Printer::match_modelname(std::string model_name) @@ -82,7 +83,10 @@ void H89Printer::shutdown() void H89Printer::set_printer_type(printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/device/iec/modem.cpp b/lib/device/iec/modem.cpp index 06bb83c80..80c0e7cef 100644 --- a/lib/device/iec/modem.cpp +++ b/lib/device/iec/modem.cpp @@ -13,6 +13,7 @@ iecModem::~iecModem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } } diff --git a/lib/device/iec/network.cpp b/lib/device/iec/network.cpp index d58490bd5..acf2becfc 100644 --- a/lib/device/iec/network.cpp +++ b/lib/device/iec/network.cpp @@ -53,6 +53,11 @@ iecNetwork::~iecNetwork() delete receiveBuffer[i]; delete transmitBuffer[i]; delete specialBuffer[i]; + protocol[i] = nullptr; + json[i] = nullptr; + receiveBuffer[i] = nullptr; + transmitBuffer[i] = nullptr; + specialBuffer[i] = nullptr; } } diff --git a/lib/device/iec/printer.cpp b/lib/device/iec/printer.cpp index 50216859f..710744994 100755 --- a/lib/device/iec/printer.cpp +++ b/lib/device/iec/printer.cpp @@ -22,6 +22,7 @@ constexpr const char *const iecPrinter::printer_model_str[PRINTER_INVALID]; iecPrinter::~iecPrinter() { delete _pptr; + _pptr = nullptr; } // write for W commands @@ -59,7 +60,10 @@ void iecPrinter::status() void iecPrinter::set_printer_type(iecPrinter::printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/device/iwm/modem.cpp b/lib/device/iwm/modem.cpp index c6155a9db..a30f79758 100644 --- a/lib/device/iwm/modem.cpp +++ b/lib/device/iwm/modem.cpp @@ -105,6 +105,7 @@ iwmModem::~iwmModem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } if (telnet != nullptr) diff --git a/lib/device/iwm/network.cpp b/lib/device/iwm/network.cpp index fbb79c314..6f37df71a 100755 --- a/lib/device/iwm/network.cpp +++ b/lib/device/iwm/network.cpp @@ -55,6 +55,14 @@ iwmNetwork::~iwmNetwork() delete receiveBuffer; delete transmitBuffer; delete specialBuffer; + receiveBuffer = nullptr; + transmitBuffer = nullptr; + specialBuffer = nullptr; + + if (protocol != nullptr) + delete protocol; + + protocol = nullptr; } /** iwm COMMANDS ***************************************************************/ diff --git a/lib/device/iwm/printer.cpp b/lib/device/iwm/printer.cpp index ad5f62d89..8fca1ec42 100644 --- a/lib/device/iwm/printer.cpp +++ b/lib/device/iwm/printer.cpp @@ -18,6 +18,7 @@ iwmPrinter::iwmPrinter(FileSystem *filesystem, printer_type printer_type) iwmPrinter::~iwmPrinter() { delete _pptr; + _pptr = nullptr; } void iwmPrinter::send_status_reply_packet() @@ -208,7 +209,10 @@ void iwmPrinter::process(iwm_decoded_cmd_t cmd) void iwmPrinter::set_printer_type(iwmPrinter::printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/device/mac/modem.cpp b/lib/device/mac/modem.cpp index 5f46bf6c2..9ce8172af 100644 --- a/lib/device/mac/modem.cpp +++ b/lib/device/mac/modem.cpp @@ -29,6 +29,7 @@ macModem::~macModem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } // if (telnet != nullptr) @@ -152,6 +153,7 @@ iwmModem::~iwmModem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } if (telnet != nullptr) diff --git a/lib/device/mac/printer.cpp b/lib/device/mac/printer.cpp index 123de7632..72e0930e0 100644 --- a/lib/device/mac/printer.cpp +++ b/lib/device/mac/printer.cpp @@ -17,6 +17,7 @@ macPrinter::macPrinter(FileSystem *filesystem, printer_type printer_type) macPrinter::~macPrinter() { delete _pptr; + _pptr = nullptr; } /** @@ -41,7 +42,10 @@ void macPrinter::process(mac_cmd_t cmd) void macPrinter::set_printer_type(macPrinter::printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/device/new/disk.cpp b/lib/device/new/disk.cpp index 338fadc63..8836936dd 100755 --- a/lib/device/new/disk.cpp +++ b/lib/device/new/disk.cpp @@ -23,7 +23,10 @@ adamDisk::adamDisk() adamDisk::~adamDisk() { if (_media != nullptr) + { delete _media; + _media = nullptr; + } } void adamDisk::reset() diff --git a/lib/device/new/keyboard.cpp b/lib/device/new/keyboard.cpp index e6acdc646..b9170014d 100644 --- a/lib/device/new/keyboard.cpp +++ b/lib/device/new/keyboard.cpp @@ -19,6 +19,7 @@ adamKeyboard::~adamKeyboard() // vTaskDelete(kbTask); server->stop(); delete server; + server = nullptr; } void adamKeyboard::adamnet_control_status() diff --git a/lib/device/new/modem.cpp b/lib/device/new/modem.cpp index bc6ff0d08..b815b71a4 100755 --- a/lib/device/new/modem.cpp +++ b/lib/device/new/modem.cpp @@ -87,6 +87,7 @@ adamModem::~adamModem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } if (telnet != nullptr) diff --git a/lib/device/new/network.cpp b/lib/device/new/network.cpp index 091522f13..2a7802c70 100755 --- a/lib/device/new/network.cpp +++ b/lib/device/new/network.cpp @@ -58,6 +58,14 @@ adamNetwork::~adamNetwork() delete receiveBuffer; delete transmitBuffer; delete specialBuffer; + receiveBuffer = nullptr; + transmitBuffer = nullptr; + specialBuffer = nullptr; + + if (protocol != nullptr) + delete protocol; + + protocol = nullptr; } /** ADAM COMMANDS ***************************************************************/ diff --git a/lib/device/new/printer.cpp b/lib/device/new/printer.cpp index 9309434ca..7288d5f8c 100755 --- a/lib/device/new/printer.cpp +++ b/lib/device/new/printer.cpp @@ -54,6 +54,7 @@ adamPrinter::~adamPrinter() { vTaskDelete(thPrinter); delete _pptr; + _pptr = nullptr; } adamPrinter::printer_type adamPrinter::match_modelname(std::string model_name) @@ -140,7 +141,10 @@ void adamPrinter::shutdown() void adamPrinter::set_printer_type(printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/device/new/serial.cpp b/lib/device/new/serial.cpp index 9cc1a8ea0..757f3d362 100644 --- a/lib/device/new/serial.cpp +++ b/lib/device/new/serial.cpp @@ -40,6 +40,7 @@ adamSerial::~adamSerial() { server->stop(); delete server; + server = nullptr; } void adamSerial::command_recv() diff --git a/lib/device/rc2014/disk.cpp b/lib/device/rc2014/disk.cpp index b52e1c1df..aba142aaf 100644 --- a/lib/device/rc2014/disk.cpp +++ b/lib/device/rc2014/disk.cpp @@ -25,7 +25,10 @@ rc2014Disk::rc2014Disk() rc2014Disk::~rc2014Disk() { if (_media != nullptr) + { delete _media; + _media = nullptr; + } } // Read disk data and send to computer diff --git a/lib/device/rc2014/modem.cpp b/lib/device/rc2014/modem.cpp index 23b941b0d..39ae005f7 100644 --- a/lib/device/rc2014/modem.cpp +++ b/lib/device/rc2014/modem.cpp @@ -97,6 +97,7 @@ rc2014Modem::~rc2014Modem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } if (telnet != nullptr) diff --git a/lib/device/rc2014/network.cpp b/lib/device/rc2014/network.cpp index 5075cdc13..1b5eb4005 100644 --- a/lib/device/rc2014/network.cpp +++ b/lib/device/rc2014/network.cpp @@ -58,6 +58,14 @@ rc2014Network::~rc2014Network() delete receiveBuffer; delete transmitBuffer; delete specialBuffer; + receiveBuffer = nullptr; + transmitBuffer = nullptr; + specialBuffer = nullptr; + + if (protocol != nullptr) + delete protocol; + + protocol = nullptr; } /** rc2014 COMMANDS ***************************************************************/ diff --git a/lib/device/rc2014/printer.cpp b/lib/device/rc2014/printer.cpp index 64ce0ea07..22d60e7ac 100644 --- a/lib/device/rc2014/printer.cpp +++ b/lib/device/rc2014/printer.cpp @@ -39,6 +39,7 @@ rc2014Printer::rc2014Printer(FileSystem *filesystem, printer_type print_type) rc2014Printer::~rc2014Printer() { delete _pptr; + _pptr = nullptr; } rc2014Printer::printer_type rc2014Printer::match_modelname(std::string model_name) @@ -168,7 +169,10 @@ void rc2014Printer::shutdown() void rc2014Printer::set_printer_type(printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/device/rs232/disk.cpp b/lib/device/rs232/disk.cpp index 1f08c0cb1..5ca3e71ba 100755 --- a/lib/device/rs232/disk.cpp +++ b/lib/device/rs232/disk.cpp @@ -227,7 +227,10 @@ mediatype_t rs232Disk::mount(FILE *f, const char *filename, uint32_t disksize, m rs232Disk::~rs232Disk() { if (_disk != nullptr) + { delete _disk; + _disk = nullptr; + } } // Unmount disk file diff --git a/lib/device/rs232/modem.cpp b/lib/device/rs232/modem.cpp index d15739036..37aeffe29 100755 --- a/lib/device/rs232/modem.cpp +++ b/lib/device/rs232/modem.cpp @@ -107,6 +107,7 @@ rs232Modem::~rs232Modem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } if (telnet != nullptr) @@ -160,6 +161,9 @@ void rs232Modem::rs232_poll_3(uint8_t device, uint8_t aux1, uint8_t aux2) if (respond == false) return; + // HACK TO GET IT TO COMPILE, TODO: FIX RS232 + int filesize = 100; + // Simply return (without ACK) if we failed to get this if (filesize < 0) return; @@ -254,7 +258,10 @@ void rs232Modem::rs232_send_firmware(uint8_t loadcommand) } // Load firmware from file - uint8_t *code; + // HACK TO GET RS232 TO COMPILE, TODO: FIX RS232 + uint8_t *code = NULL; + int codesize = 100; + // NAK if we failed to get this if (codesize < 0 || code == NULL) { diff --git a/lib/device/rs232/network.cpp b/lib/device/rs232/network.cpp index 1ec1e91a3..c3109e4c0 100755 --- a/lib/device/rs232/network.cpp +++ b/lib/device/rs232/network.cpp @@ -70,6 +70,14 @@ rs232Network::~rs232Network() delete receiveBuffer; delete transmitBuffer; delete specialBuffer; + receiveBuffer = nullptr; + transmitBuffer = nullptr; + specialBuffer = nullptr; + + if (protocol != nullptr) + delete protocol; + + protocol = nullptr; } /** RS232 COMMANDS ***************************************************************/ diff --git a/lib/device/rs232/printer.cpp b/lib/device/rs232/printer.cpp index f1f38a29d..5b38817be 100755 --- a/lib/device/rs232/printer.cpp +++ b/lib/device/rs232/printer.cpp @@ -38,6 +38,7 @@ constexpr const char * const rs232Printer::printer_model_str[PRINTER_INVALID]; rs232Printer::~rs232Printer() { delete _pptr; + _pptr = nullptr; } // write for W commands @@ -160,7 +161,10 @@ void rs232Printer::rs232_status() void rs232Printer::set_printer_type(rs232Printer::printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/device/s100spi/disk.cpp b/lib/device/s100spi/disk.cpp index eeb7794a4..a61584a72 100644 --- a/lib/device/s100spi/disk.cpp +++ b/lib/device/s100spi/disk.cpp @@ -18,7 +18,10 @@ s100spiDisk::s100spiDisk() s100spiDisk::~s100spiDisk() { if (_media != nullptr) + { delete _media; + _media = nullptr; + } } void s100spiDisk::reset() diff --git a/lib/device/s100spi/modem.cpp b/lib/device/s100spi/modem.cpp index c52d7e1f6..223ade587 100644 --- a/lib/device/s100spi/modem.cpp +++ b/lib/device/s100spi/modem.cpp @@ -87,6 +87,7 @@ s100spiModem::~s100spiModem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } if (telnet != nullptr) diff --git a/lib/device/s100spi/network.cpp b/lib/device/s100spi/network.cpp index 40e5a06fc..cebf34537 100644 --- a/lib/device/s100spi/network.cpp +++ b/lib/device/s100spi/network.cpp @@ -58,6 +58,14 @@ s100spiNetwork::~s100spiNetwork() delete receiveBuffer; delete transmitBuffer; delete specialBuffer; + receiveBuffer = nullptr; + transmitBuffer = nullptr; + specialBuffer = nullptr; + + if (protocol != nullptr) + delete protocol; + + protocol = nullptr; } /** s100spi COMMANDS ***************************************************************/ diff --git a/lib/device/s100spi/printer.cpp b/lib/device/s100spi/printer.cpp index f3ac785f5..f0337d7e5 100644 --- a/lib/device/s100spi/printer.cpp +++ b/lib/device/s100spi/printer.cpp @@ -54,6 +54,7 @@ s100spiPrinter::~s100spiPrinter() { vTaskDelete(thPrinter); delete _pptr; + _pptr = nullptr; } s100spiPrinter::printer_type s100spiPrinter::match_modelname(std::string model_name) @@ -122,7 +123,10 @@ void s100spiPrinter::shutdown() void s100spiPrinter::set_printer_type(printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/device/s100spi/printer.h b/lib/device/s100spi/printer.h index ce4865032..f685614dc 100644 --- a/lib/device/s100spi/printer.h +++ b/lib/device/s100spi/printer.h @@ -20,7 +20,7 @@ class s100spiPrinter : public virtualDevice { protected: // SIO THINGS - TaskHandle_t *thPrinter; + TaskHandle_t thPrinter; uint8_t _buffer[16]; diff --git a/lib/device/sio/disk.cpp b/lib/device/sio/disk.cpp index 09b0dbf4a..aae331026 100755 --- a/lib/device/sio/disk.cpp +++ b/lib/device/sio/disk.cpp @@ -260,7 +260,10 @@ mediatype_t sioDisk::mount(FILE *f, const char *filename, uint32_t disksize, med sioDisk::~sioDisk() { if (_disk != nullptr) + { delete _disk; + _disk = nullptr; + } } // Unmount disk file diff --git a/lib/device/sio/network.cpp b/lib/device/sio/network.cpp index aaf282ace..0baa235b4 100755 --- a/lib/device/sio/network.cpp +++ b/lib/device/sio/network.cpp @@ -68,6 +68,14 @@ sioNetwork::~sioNetwork() delete receiveBuffer; delete transmitBuffer; delete specialBuffer; + receiveBuffer = nullptr; + transmitBuffer = nullptr; + specialBuffer = nullptr; + + if (protocol != nullptr) + delete protocol; + + protocol = nullptr; } /** SIO COMMANDS ***************************************************************/ @@ -211,7 +219,10 @@ void sioNetwork::sio_close() protocol = nullptr; if (json != nullptr) + { delete json; + json = nullptr; + } if (newData) free(newData); @@ -1164,6 +1175,7 @@ void sioNetwork::sio_set_timer_rate() void sioNetwork::sio_do_idempotent_command_80() { + Debug_printf("sioNetwork::sio_do_idempotent_command_80()\r\n"); sio_ack(); parse_and_instantiate_protocol(); diff --git a/lib/device/sio/printer.cpp b/lib/device/sio/printer.cpp index fc631257f..981c925de 100755 --- a/lib/device/sio/printer.cpp +++ b/lib/device/sio/printer.cpp @@ -38,6 +38,7 @@ constexpr const char * const sioPrinter::printer_model_str[PRINTER_INVALID]; sioPrinter::~sioPrinter() { delete _pptr; + _pptr = nullptr; } // write for W commands @@ -160,7 +161,10 @@ void sioPrinter::sio_status() void sioPrinter::set_printer_type(sioPrinter::printer_type printer_type) { // Destroy any current printer emu object - delete _pptr; + if (_pptr != nullptr) + { + delete _pptr; + } _ptype = printer_type; switch (printer_type) diff --git a/lib/ftp/fnFTP.cpp b/lib/ftp/fnFTP.cpp index f15072e7f..dd70de076 100644 --- a/lib/ftp/fnFTP.cpp +++ b/lib/ftp/fnFTP.cpp @@ -650,6 +650,9 @@ fnFTP::~fnFTP() delete control; if (data != nullptr) delete data; + + control = nullptr; + data = nullptr; } bool fnFTP::login(const string &_username, const string &_password, const string &_hostname, unsigned short _port) diff --git a/lib/fuji/fujiHost.cpp b/lib/fuji/fujiHost.cpp index 9e74b10f9..f027b79f2 100755 --- a/lib/fuji/fujiHost.cpp +++ b/lib/fuji/fujiHost.cpp @@ -356,6 +356,7 @@ int fujiHost::unmount_tnfs() if (_fs != nullptr) { delete _fs; + _fs = nullptr; } return 0; diff --git a/lib/media/atari/diskTypeAtx.cpp b/lib/media/atari/diskTypeAtx.cpp index 25e1275e5..c5792834c 100755 --- a/lib/media/atari/diskTypeAtx.cpp +++ b/lib/media/atari/diskTypeAtx.cpp @@ -70,6 +70,8 @@ AtxTrack::~AtxTrack() { if (data != nullptr) delete[] data; + + data = nullptr; }; AtxTrack::AtxTrack(){ @@ -494,6 +496,7 @@ bool MediaTypeATX::_load_atx_chunk_sector_data(chunk_header_t &chunk_hdr, AtxTra { Debug_printf("failed reading %d sector data chunk bytes (%d, %d)\r\n", data_size, i, errno); delete[] track.data; + track.data = nullptr; return false; } diff --git a/lib/modem/modem.cpp b/lib/modem/modem.cpp index 1870e991b..830b23c11 100755 --- a/lib/modem/modem.cpp +++ b/lib/modem/modem.cpp @@ -105,6 +105,7 @@ modem::~modem() if (modemSniffer != nullptr) { delete modemSniffer; + modemSniffer = nullptr; } if (telnet != nullptr) diff --git a/lib/network-protocol/FS.cpp b/lib/network-protocol/FS.cpp index cac9232fb..f29da865e 100755 --- a/lib/network-protocol/FS.cpp +++ b/lib/network-protocol/FS.cpp @@ -389,6 +389,7 @@ void NetworkProtocolFS::resolve() bool NetworkProtocolFS::perform_idempotent_80(EdUrlParser *url, cmdFrame_t *cmdFrame) { + Debug_printf("NetworkProtocolFS::perform_idempotent_80, url: %s\r\n", url->toString().c_str()); switch (cmdFrame->comnd) { case 0x20: diff --git a/lib/network-protocol/FTP.cpp b/lib/network-protocol/FTP.cpp index 94618f011..138b974c2 100755 --- a/lib/network-protocol/FTP.cpp +++ b/lib/network-protocol/FTP.cpp @@ -28,6 +28,7 @@ NetworkProtocolFTP::~NetworkProtocolFTP() { Debug_printf("NetworkProtocolFTP::dtor\r\n"); delete ftp; + ftp = nullptr; } bool NetworkProtocolFTP::open_file_handle() diff --git a/lib/network-protocol/HTTP.cpp b/lib/network-protocol/HTTP.cpp index cd0eee849..ba7dd8c51 100755 --- a/lib/network-protocol/HTTP.cpp +++ b/lib/network-protocol/HTTP.cpp @@ -238,6 +238,7 @@ bool NetworkProtocolHTTP::umount() return false; delete client; + client = nullptr; return false; } @@ -669,6 +670,7 @@ bool NetworkProtocolHTTP::rename(EdUrlParser *url, cmdFrame_t *cmdFrame) bool NetworkProtocolHTTP::del(EdUrlParser *url, cmdFrame_t *cmdFrame) { + Debug_printf("NetworkProtocolHTTP::del, url: %s\r\n", url->toString().c_str()); mount(url); resultCode = client->DELETE(); diff --git a/lib/network-protocol/TCP.cpp b/lib/network-protocol/TCP.cpp index bbaa5a958..a1e9b9362 100755 --- a/lib/network-protocol/TCP.cpp +++ b/lib/network-protocol/TCP.cpp @@ -37,7 +37,6 @@ NetworkProtocolTCP::~NetworkProtocolTCP() if (server != nullptr) { delete server; - server = nullptr; } } diff --git a/lib/utils/cbuf.cpp b/lib/utils/cbuf.cpp index 23bb48b79..d0c9f9818 100644 --- a/lib/utils/cbuf.cpp +++ b/lib/utils/cbuf.cpp @@ -31,6 +31,7 @@ cbuf::cbuf(size_t size) : next(NULL), _size(size + 1), _buf(new char[size + 1]), cbuf::~cbuf() { delete[] _buf; + _buf = nullptr; } size_t cbuf::resizeAdd(size_t addSize) diff --git a/platformio-sample.ini b/platformio-sample.ini index c314a28d7..55eb76a6d 100644 --- a/platformio-sample.ini +++ b/platformio-sample.ini @@ -76,7 +76,7 @@ flash_filesystem = FLASH_SPIFFS ;build_platform = BUILD_H89 ;build_bus = H89 -;build_board = fujinet-heatkit-h89 +;build_board = fujinet-heathkit-h89 ;build_platform = BUILD_COCO ;build_bus = DRIVEWIRE