From 1f31a78bdb0c8b7b2287b00f7b64c8320d750844 Mon Sep 17 00:00:00 2001
From: Federico Terraneo <fede.tft@miosix.org>
Date: Sat, 23 Sep 2023 11:51:14 +0200
Subject: [PATCH] Fix memory leak

---
 drivers/display_st25dvdiscovery.h | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/display_st25dvdiscovery.h b/drivers/display_st25dvdiscovery.h
index 5ee40f0..148d7f8 100644
--- a/drivers/display_st25dvdiscovery.h
+++ b/drivers/display_st25dvdiscovery.h
@@ -216,7 +216,7 @@ public:
         /**
          * Default constructor, results in an invalid iterator.
          */
-        pixel_iterator(): pixelLeft(0) {}
+        pixel_iterator(): pixelLeft(0), wr(nullptr) {}
 
         /**
          * Set a pixel and move the pointer to the next one
@@ -275,13 +275,18 @@ public:
          */
         void invalidate() {}
 
+        ~pixel_iterator()
+        {
+            if(wr) delete wr;
+        }
+
     private:
 
         /**
          * Constructor
          * \param pixelLeft number of remaining pixels
          */
-        pixel_iterator(unsigned int pixelLeft): pixelLeft(pixelLeft) 
+        pixel_iterator(unsigned int pixelLeft): pixelLeft(pixelLeft)
         {
             wr = new Transaction(0x2c);
         }
@@ -408,4 +413,4 @@ private:
 } //namespace mxgui
 #endif //_BOARD_STM32F415VG_ST25DVDISCOVERY
 
-#endif //DISPLAY_ST25DVDISCOVERY_H
\ No newline at end of file
+#endif //DISPLAY_ST25DVDISCOVERY_H
-- 
GitLab