From b5ca3659288b9931fe929b5c63398592f3b204e2 Mon Sep 17 00:00:00 2001 From: Bart Trzynadlowski Date: Tue, 14 Mar 2023 11:18:20 -0700 Subject: [PATCH] NetBoard: guard against freeing null pointers and INetBoard needed a virtual destructor (was causing crashes on exit on some systems) --- Src/Network/INetBoard.h | 4 ++++ Src/Network/NetBoard.cpp | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Src/Network/INetBoard.h b/Src/Network/INetBoard.h index 2a3a1fa..20a377d 100644 --- a/Src/Network/INetBoard.h +++ b/Src/Network/INetBoard.h @@ -30,6 +30,10 @@ class INetBoard { public: + virtual ~INetBoard() + { + } + virtual void SaveState(CBlockFile* SaveState) = 0; virtual void LoadState(CBlockFile* SaveState) = 0; diff --git a/Src/Network/NetBoard.cpp b/Src/Network/NetBoard.cpp index 0e7e4b0..89fd0e2 100644 --- a/Src/Network/NetBoard.cpp +++ b/Src/Network/NetBoard.cpp @@ -111,11 +111,11 @@ #endif #ifndef SAFE_DELETE - #define SAFE_DELETE(p) delete (p); (p) = NULL; + #define SAFE_DELETE(p) if (p != nullptr) { delete (p); (p) = NULL; } #endif #ifndef SAFE_ARRAY_DELETE - #define SAFE_ARRAY_DELETE(x) delete[] x; x = NULL; + #define SAFE_ARRAY_DELETE(x) if (x != nullptr) { delete[] x; x = NULL; } #endif static int(*Runnet68kCB)(int cycles); @@ -667,7 +667,7 @@ void CNetBoard::Write8(UINT32 a, UINT8 d) case 0x80: nets->Send((const char*)CommRAM + send_offset, send_size); DebugLog("send enable off=%x size=%x\n", send_offset, send_size); - + #ifdef NET_DEBUG DebugLog("transmitting : "); if (send_size > 50) //too big for print, so...