mirror of
https://github.com/firewalkwithm3/qmk_firmware.git
synced 2024-11-22 11:30:30 +08:00
Fix memory leak in realloc failure handling (#22188)
This commit is contained in:
parent
d6b16b0df0
commit
3df155f203
|
@ -97,12 +97,13 @@ bool qp_lvgl_attach(painter_device_t device) {
|
|||
static lv_disp_draw_buf_t draw_buf;
|
||||
// Allocate a buffer for 1/10 screen size
|
||||
const size_t count_required = driver->panel_width * driver->panel_height / 10;
|
||||
color_buffer = color_buffer ? realloc(color_buffer, sizeof(lv_color_t) * count_required) : malloc(sizeof(lv_color_t) * count_required);
|
||||
if (!color_buffer) {
|
||||
void * new_color_buffer = realloc(color_buffer, sizeof(lv_color_t) * count_required);
|
||||
if (!new_color_buffer) {
|
||||
qp_dprintf("qp_lvgl_attach: fail (could not set up memory buffer)\n");
|
||||
qp_lvgl_detach();
|
||||
return false;
|
||||
}
|
||||
color_buffer = new_color_buffer;
|
||||
memset(color_buffer, 0, sizeof(lv_color_t) * count_required);
|
||||
// Initialize the display buffer.
|
||||
lv_disp_draw_buf_init(&draw_buf, color_buffer, NULL, count_required);
|
||||
|
|
Loading…
Reference in a new issue