From 020bd9ea0119ed089a92e6bea4a2dda449b218f5 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Thu, 14 Apr 2022 11:29:57 +0100 Subject: [PATCH] v2.2.9 - add the destructor to resolve issue #135 --- library.properties | 2 +- src/SparkFun_u-blox_GNSS_Arduino_Library.cpp | 27 ++++++++++++++++++++ src/SparkFun_u-blox_GNSS_Arduino_Library.h | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/library.properties b/library.properties index e6b176c..fbcebda 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun u-blox GNSS Arduino Library -version=2.2.8 +version=2.2.9 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Library for I2C, Serial and SPI Communication with u-blox GNSS modules

diff --git a/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp b/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp index 2938b12..bc4a5b7 100644 --- a/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp @@ -63,6 +63,31 @@ SFE_UBLOX_GNSS::SFE_UBLOX_GNSS(void) #endif } +SFE_UBLOX_GNSS::~SFE_UBLOX_GNSS(void) +{ + // Destructor + + end(); // Delete all allocated memory - excluding payloadCfg, payloadAuto and spiBuffer + + if (payloadCfg != NULL) + { + delete[] payloadCfg; // Created with new[] + payloadCfg = NULL; // Redundant? + } + + if (payloadAuto != NULL) + { + delete[] payloadAuto; // Created with new[] + payloadAuto = NULL; // Redundant? + } + + if (spiBuffer != NULL) + { + delete[] spiBuffer; // Created with new[] + spiBuffer = NULL; // Redundant? + } +} + // Stop all automatic message processing. Free all used RAM void SFE_UBLOX_GNSS::end(void) { @@ -70,6 +95,8 @@ void SFE_UBLOX_GNSS::end(void) // Note: payloadAuto is not deleted + // Note: spiBuffer is not deleted + if (ubxFileBuffer != NULL) // Check if RAM has been allocated for the file buffer { #ifndef SFE_UBLOX_REDUCED_PROG_MEM diff --git a/src/SparkFun_u-blox_GNSS_Arduino_Library.h b/src/SparkFun_u-blox_GNSS_Arduino_Library.h index 297d88c..5693334 100644 --- a/src/SparkFun_u-blox_GNSS_Arduino_Library.h +++ b/src/SparkFun_u-blox_GNSS_Arduino_Library.h @@ -643,6 +643,7 @@ class SFE_UBLOX_GNSS { public: SFE_UBLOX_GNSS(void); + ~SFE_UBLOX_GNSS(void); // A default of 250ms for maxWait seems fine for I2C but is not enough for SerialUSB. // If you know you are only going to be using I2C / Qwiic communication, you can