Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in realloc failure handling #22188

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions quantum/painter/lvgl/qp_lvgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ bool qp_lvgl_attach(painter_device_t device) {
// Set up lvgl display buffer
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) {
const size_t count_required = driver->panel_width * driver->panel_height / 10;
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);
Expand Down