From aa423cc1c63341b2476d0b8368f68d68d5e24ae5 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Sat, 18 Mar 2023 09:21:40 -0500 Subject: [PATCH] Free memory allocated by bitmap obj --- shared-module/displayio/Bitmap.c | 6 ++++++ shared-module/displayio/Bitmap.h | 1 + 2 files changed, 7 insertions(+) diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index 94981cbd4f..8b578005c6 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -50,6 +50,9 @@ void common_hal_displayio_bitmap_construct_from_buffer(displayio_bitmap_t *self, self->stride = stride(width, bits_per_value); if (!data) { data = m_malloc(self->stride * height * sizeof(uint32_t), false); + self->data_alloc = true; + } else { + self->data_alloc = false; } self->data = data; self->read_only = read_only; @@ -80,6 +83,9 @@ void common_hal_displayio_bitmap_construct_from_buffer(displayio_bitmap_t *self, } void common_hal_displayio_bitmap_deinit(displayio_bitmap_t *self) { + if (self->data_alloc) { + m_free(self->data); + } self->data = NULL; } diff --git a/shared-module/displayio/Bitmap.h b/shared-module/displayio/Bitmap.h index 0373ae80c5..2025e56282 100644 --- a/shared-module/displayio/Bitmap.h +++ b/shared-module/displayio/Bitmap.h @@ -45,6 +45,7 @@ typedef struct { displayio_area_t dirty_area; uint16_t bitmask; bool read_only; + bool data_alloc; // did bitmap allocate data or someone else } displayio_bitmap_t; void displayio_bitmap_finish_refresh(displayio_bitmap_t *self);