Skip to content

Commit

Permalink
nulls after deletes
Browse files Browse the repository at this point in the history
General cleanup by having consistent approach to setting null after deleting a reference.
  • Loading branch information
markjfisher committed Oct 18, 2023
1 parent 66aa040 commit 929e74d
Show file tree
Hide file tree
Showing 62 changed files with 235 additions and 20 deletions.
3 changes: 3 additions & 0 deletions lib/TNFSlib/tnfslibMountInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions lib/bus/s100spi/s100spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions lib/device/adamnet/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ adamDisk::adamDisk()
adamDisk::~adamDisk()
{
if (_media != nullptr)
{
delete _media;
_media = nullptr;
}
}

void adamDisk::reset()
Expand Down
1 change: 1 addition & 0 deletions lib/device/adamnet/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ adamKeyboard::~adamKeyboard()
// vTaskDelete(kbTask);
server->stop();
delete server;
server = nullptr;
}

void adamKeyboard::adamnet_control_status()
Expand Down
1 change: 1 addition & 0 deletions lib/device/adamnet/modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ adamModem::~adamModem()
if (modemSniffer != nullptr)
{
delete modemSniffer;
modemSniffer = nullptr;
}

if (telnet != nullptr)
Expand Down
3 changes: 3 additions & 0 deletions lib/device/adamnet/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ adamNetwork::~adamNetwork()
delete receiveBuffer;
delete transmitBuffer;
delete specialBuffer;
receiveBuffer = nullptr;
transmitBuffer = nullptr;
specialBuffer = nullptr;

if (protocol != nullptr)
delete protocol;
Expand Down
8 changes: 7 additions & 1 deletion lib/device/adamnet/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ adamPrinter::~adamPrinter()
vTaskDelete(thPrinter);

if (_pptr != nullptr)
{
delete _pptr;
_pptr = nullptr;
}

vQueueDelete(pxq);
}
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions lib/device/comlynx/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ lynxDisk::lynxDisk()
lynxDisk::~lynxDisk()
{
if (_media != nullptr)
{
delete _media;
_media = nullptr;
}
}

void lynxDisk::reset()
Expand Down
1 change: 1 addition & 0 deletions lib/device/comlynx/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ lynxKeyboard::~lynxKeyboard()
// vTaskDelete(kbTask);
server->stop();
delete server;
server = nullptr;
}

void lynxKeyboard::comlynx_control_status()
Expand Down
1 change: 1 addition & 0 deletions lib/device/comlynx/modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ lynxModem::~lynxModem()
if (modemSniffer != nullptr)
{
delete modemSniffer;
modemSniffer = nullptr;
}

if (telnet != nullptr)
Expand Down
8 changes: 8 additions & 0 deletions lib/device/comlynx/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***************************************************************/
Expand Down
8 changes: 7 additions & 1 deletion lib/device/comlynx/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ lynxPrinter::~lynxPrinter()
vTaskDelete(thPrinter);

if (_pptr != nullptr)
{
delete _pptr;
_pptr = nullptr;
}
}

void lynxPrinter::start_printer_task()
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions lib/device/cx16_i2c/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/device/cx16_i2c/modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cx16Modem::cx16Modem(FileSystem *_fs, bool snifferEnable)
cx16Modem::~cx16Modem()
{
delete modemSniffer;
modemSniffer = nullptr;
}

#endif /* BUILD_CX16 */
2 changes: 1 addition & 1 deletion lib/device/cx16_i2c/modem.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
class cx16Modem : public virtualDevice
{
private:
ModemSniffer* modemSniffer;
FileSystem *activeFS;
ModemSniffer* modemSniffer;
time_t _lasttime = 0;

public:
Expand Down
11 changes: 9 additions & 2 deletions lib/device/cx16_i2c/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/device/drivewire/modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ drivewireModem::~drivewireModem()
if (modemSniffer != nullptr)
{
delete modemSniffer;
modemSniffer = nullptr;
}

if (telnet != nullptr)
Expand Down
11 changes: 11 additions & 0 deletions lib/device/drivewire/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***************************************************************/
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions lib/device/drivewire/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/device/h89/modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ H89Modem::~H89Modem()
if (modemSniffer != nullptr)
{
delete modemSniffer;
modemSniffer = nullptr;
}

if (telnet != nullptr)
Expand Down
8 changes: 8 additions & 0 deletions lib/device/h89/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***************************************************************/
Expand Down
6 changes: 5 additions & 1 deletion lib/device/h89/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ H89Printer::~H89Printer()
{
//vTaskDelete(thPrinter);
delete _pptr;
_pptr = nullptr;
}

H89Printer::printer_type H89Printer::match_modelname(std::string model_name)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/device/iec/modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ iecModem::~iecModem()
if (modemSniffer != nullptr)
{
delete modemSniffer;
modemSniffer = nullptr;
}
}

Expand Down
5 changes: 5 additions & 0 deletions lib/device/iec/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
6 changes: 5 additions & 1 deletion lib/device/iec/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ constexpr const char *const iecPrinter::printer_model_str[PRINTER_INVALID];
iecPrinter::~iecPrinter()
{
delete _pptr;
_pptr = nullptr;
}

// write for W commands
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/device/iwm/modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ iwmModem::~iwmModem()
if (modemSniffer != nullptr)
{
delete modemSniffer;
modemSniffer = nullptr;
}

if (telnet != nullptr)
Expand Down
8 changes: 8 additions & 0 deletions lib/device/iwm/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***************************************************************/
Expand Down
6 changes: 5 additions & 1 deletion lib/device/iwm/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ iwmPrinter::iwmPrinter(FileSystem *filesystem, printer_type printer_type)
iwmPrinter::~iwmPrinter()
{
delete _pptr;
_pptr = nullptr;
}

void iwmPrinter::send_status_reply_packet()
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 929e74d

Please sign in to comment.