Skip to content

Commit ef455df

Browse files
visitorckwNathan
authored and
Nathan
committed
Fix memory leak in realloc failure handling (qmk#22188)
1 parent cb03b2e commit ef455df

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

quantum/painter/lvgl/qp_lvgl.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ bool qp_lvgl_attach(painter_device_t device) {
9696
// Set up lvgl display buffer
9797
static lv_disp_draw_buf_t draw_buf;
9898
// Allocate a buffer for 1/10 screen size
99-
const size_t count_required = driver->panel_width * driver->panel_height / 10;
100-
color_buffer = color_buffer ? realloc(color_buffer, sizeof(lv_color_t) * count_required) : malloc(sizeof(lv_color_t) * count_required);
101-
if (!color_buffer) {
99+
const size_t count_required = driver->panel_width * driver->panel_height / 10;
100+
void * new_color_buffer = realloc(color_buffer, sizeof(lv_color_t) * count_required);
101+
if (!new_color_buffer) {
102102
qp_dprintf("qp_lvgl_attach: fail (could not set up memory buffer)\n");
103103
qp_lvgl_detach();
104104
return false;
105105
}
106+
color_buffer = new_color_buffer;
106107
memset(color_buffer, 0, sizeof(lv_color_t) * count_required);
107108
// Initialize the display buffer.
108109
lv_disp_draw_buf_init(&draw_buf, color_buffer, NULL, count_required);

0 commit comments

Comments
 (0)