From 5cc6f1267618648751c7eb76f77836018d30bf39 Mon Sep 17 00:00:00 2001 From: caternuson Date: Thu, 2 Sep 2021 10:08:42 -0700 Subject: [PATCH] tweak memory alloc and cleanup --- Adafruit_CCS811.cpp | 8 +++++++- Adafruit_CCS811.h | 2 +- library.properties | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Adafruit_CCS811.cpp b/Adafruit_CCS811.cpp index 42a0266..40f7adb 100644 --- a/Adafruit_CCS811.cpp +++ b/Adafruit_CCS811.cpp @@ -1,5 +1,10 @@ #include "Adafruit_CCS811.h" +Adafruit_CCS811::~Adafruit_CCS811(void) { + if (i2c_dev) + delete i2c_dev; +} + /**************************************************************************/ /*! @brief Setups the I2C interface and hardware and checks for communication. @@ -10,7 +15,8 @@ */ /**************************************************************************/ bool Adafruit_CCS811::begin(uint8_t addr, TwoWire *theWire) { - + if (i2c_dev) + delete i2c_dev; i2c_dev = new Adafruit_I2CDevice(addr, theWire); if (!i2c_dev->begin()) { return false; diff --git a/Adafruit_CCS811.h b/Adafruit_CCS811.h index 94e3e55..0a5224a 100644 --- a/Adafruit_CCS811.h +++ b/Adafruit_CCS811.h @@ -67,7 +67,7 @@ class Adafruit_CCS811 { public: // constructors Adafruit_CCS811(void){}; - ~Adafruit_CCS811(void){}; + ~Adafruit_CCS811(void); bool begin(uint8_t addr = CCS811_ADDRESS, TwoWire *theWire = &Wire); diff --git a/library.properties b/library.properties index 2ce9c8d..944e098 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit CCS811 Library -version=1.1.0 +version=1.1.1 author=Adafruit maintainer=Adafruit sentence=This is a library for the Adafruit CCS811 I2C gas sensor breakout.