Skip to content

Commit aa423cc

Browse files
committed
Free memory allocated by bitmap obj
1 parent 07e8367 commit aa423cc

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

shared-module/displayio/Bitmap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ void common_hal_displayio_bitmap_construct_from_buffer(displayio_bitmap_t *self,
5050
self->stride = stride(width, bits_per_value);
5151
if (!data) {
5252
data = m_malloc(self->stride * height * sizeof(uint32_t), false);
53+
self->data_alloc = true;
54+
} else {
55+
self->data_alloc = false;
5356
}
5457
self->data = data;
5558
self->read_only = read_only;
@@ -80,6 +83,9 @@ void common_hal_displayio_bitmap_construct_from_buffer(displayio_bitmap_t *self,
8083
}
8184

8285
void common_hal_displayio_bitmap_deinit(displayio_bitmap_t *self) {
86+
if (self->data_alloc) {
87+
m_free(self->data);
88+
}
8389
self->data = NULL;
8490
}
8591

shared-module/displayio/Bitmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ typedef struct {
4545
displayio_area_t dirty_area;
4646
uint16_t bitmask;
4747
bool read_only;
48+
bool data_alloc; // did bitmap allocate data or someone else
4849
} displayio_bitmap_t;
4950

5051
void displayio_bitmap_finish_refresh(displayio_bitmap_t *self);

0 commit comments

Comments
 (0)