diff --git a/Adafruit_Thermal.cpp b/Adafruit_Thermal.cpp index bef02cb..5090e07 100644 --- a/Adafruit_Thermal.cpp +++ b/Adafruit_Thermal.cpp @@ -72,6 +72,13 @@ Adafruit_Thermal::Adafruit_Thermal(Stream *s, uint8_t dtr) dtrEnabled = false; } +// Destructor +Adafruit_Thermal::~Adafruit_Thermal(){ + if (stream != nullptr) { + delete stream; + } +} + // This method sets the estimated completion time for a just-issued task. void Adafruit_Thermal::timeoutSet(unsigned long x) { if (!dtrEnabled) diff --git a/Adafruit_Thermal.h b/Adafruit_Thermal.h index bbde73c..ea9a886 100644 --- a/Adafruit_Thermal.h +++ b/Adafruit_Thermal.h @@ -101,6 +101,8 @@ class Adafruit_Thermal : public Print { * @param dtr Data Terminal Ready control */ Adafruit_Thermal(Stream *s = &Serial, uint8_t dtr = 255); + + ~Adafruit_Thermal(); size_t /*! @@ -337,7 +339,7 @@ class Adafruit_Thermal : public Print { hasPaper(); private: - Stream *stream; + Stream *stream = nullptr; uint8_t printMode, prevByte, // Last character issued to printer column, // Last horizontal column printed