fix(graphics): crash and leak fixes across display drivers (#11455)

* fix(graphics): crash and leak fixes across display drivers

- TFTDisplay (portduino): _touch_instance was an uninitialized member,
  and the touch-config block only assigns it for xpt2046/stmpe610/
  ft5x06 while the guard accepts any configured module. A gt911 entry
  in config.yaml (supported by the color-UI path) reached
  _touch_instance->config() through an indeterminate pointer. Initialize
  to nullptr and guard the config block.

- Screen: the destructor freed normalFrames but leaked the owned
  dispdev (driver + framebuffer) and ui objects. Screen is genuinely
  destroyed on the portduino reboot path (screen = nullptr in
  Power.cpp).

- EInkDisplay2: GxEPD2_BW's constructor takes the low-level driver by
  value and stores a copy, so the 'new EINK_DISPLAY_MODEL' at nine
  sites was orphaned the moment connect() returned. Pass temporaries,
  as GxEPD2Multi already does.

- EInkParallelDisplay: the async full-refresh task cleared
  asyncFullRunning before nulling asyncTaskHandle, so the destructor
  could observe running==false with a stale handle and vTaskDelete a
  freed TCB. Null the handle first (same ordering fix the
  eink/Drivers/EInkParallel.cpp sibling already carries).

- Panel_sdl: initFrameBuffer only null-checked the first of its three
  allocations and returned true regardless, leaving the line array
  full of null+offset garbage on failure; later redraws would write
  through those. Check all three, release partial allocations, and
  return false.

* fix(graphics): propagate Panel_sdl framebuffer allocation failure from init()

Per review: initFrameBuffer() can now fail cleanly, so init() must not
register the monitor and report success when it does.
This commit is contained in:
Ben Meadors
2026-08-18 12:10:03 +00:00
committed by GitHub
parent c308d0aca4
commit e1ea653a45
5 files changed
+72 -42

No files matched your search

+21 -17
View File
@@ -821,7 +821,7 @@ class LGFX : public lgfx::LGFX_Device
{
lgfx::Bus_SPI _bus_instance;
lgfx::ITouch *_touch_instance;
lgfx::ITouch *_touch_instance = nullptr;
public:
lgfx::Panel_Device *_panel_instance;
@@ -891,24 +891,28 @@ class LGFX : public lgfx::LGFX_Device
} else if (portduino_config.touchscreenModule == ft5x06) {
_touch_instance = new lgfx::Touch_FT5x06;
}
auto touch_cfg = _touch_instance->config();
// Not every module in the config enum has a branch above (gt911 is handled by the
// color-UI path in tftSetup.cpp), so the pointer can legitimately still be null here.
if (_touch_instance) {
auto touch_cfg = _touch_instance->config();
touch_cfg.pin_cs = portduino_config.touchscreenCS.pin;
touch_cfg.x_min = 0;
touch_cfg.x_max = portduino_config.displayHeight - 1;
touch_cfg.y_min = 0;
touch_cfg.y_max = portduino_config.displayWidth - 1;
touch_cfg.pin_int = portduino_config.touchscreenIRQ.pin;
touch_cfg.bus_shared = true;
touch_cfg.offset_rotation = portduino_config.touchscreenRotate;
if (portduino_config.touchscreenI2CAddr != -1) {
touch_cfg.i2c_addr = portduino_config.touchscreenI2CAddr;
} else {
touch_cfg.spi_host = portduino_config.touchscreen_spi_dev_int;
touch_cfg.pin_cs = portduino_config.touchscreenCS.pin;
touch_cfg.x_min = 0;
touch_cfg.x_max = portduino_config.displayHeight - 1;
touch_cfg.y_min = 0;
touch_cfg.y_max = portduino_config.displayWidth - 1;
touch_cfg.pin_int = portduino_config.touchscreenIRQ.pin;
touch_cfg.bus_shared = true;
touch_cfg.offset_rotation = portduino_config.touchscreenRotate;
if (portduino_config.touchscreenI2CAddr != -1) {
touch_cfg.i2c_addr = portduino_config.touchscreenI2CAddr;
} else {
touch_cfg.spi_host = portduino_config.touchscreen_spi_dev_int;
}
_touch_instance->config(touch_cfg);
_panel_instance->setTouch(_touch_instance);
}
_touch_instance->config(touch_cfg);
_panel_instance->setTouch(_touch_instance);
}
#if defined(SDL_h_)
if (portduino_config.displayPanel == x11) {