Skip to content

fix: improve memory safety and UART driver stability#133

Open
H3rD3m1s3MyR1s3 wants to merge 2 commits intoDroneBridge:masterfrom
H3rD3m1s3MyR1s3:jj/fix/memory-and-driver-stability
Open

fix: improve memory safety and UART driver stability#133
H3rD3m1s3MyR1s3 wants to merge 2 commits intoDroneBridge:masterfrom
H3rD3m1s3MyR1s3:jj/fix/memory-and-driver-stability

Conversation

@H3rD3m1s3MyR1s3
Copy link
Copy Markdown
Contributor

@H3rD3m1s3MyR1s3 H3rD3m1s3MyR1s3 commented Feb 24, 2026

PR Description:

 This PR addresses several stability issues and potential crash points in t
  ESP32 control module, specifically focusing on memory management and
  hardware driver lifecycle.

 ### Key Changes:

 1. **Memory Safety (Heap Exhaustion Protection):**
    - Added `NULL` checks for `malloc()` calls in `db_send_to_all_espnow` a
      the Bluetooth (BLE) transmission path.
    - **Benefit:** Prevents Kernel Panics and random reboots if the system
      runs low on memory during high MAVLink throughput. The system will now log
      an error and skip the packet instead of crashing.

 2. **UART Driver Management:**
   - Added a `uart_is_driver_installed()` check before calling
    `uart_driver_install()` in `db_serial.c`.
   - **Benefit:** Prevents resource leaks and driver initialization errors
    when the control module is restarted (e.g., after a settings change in the
    Web UI).
  1. Buffer Protection:

    • Implemented a missing bounds check in handle_internal_telemetry.
    • Benefit: Prevents memory corruption/over-reads if a malformed or
      truncated internal telemetry packet is received from another station.
  2. Hardware Efficiency:

    • Added a zero-length guard in write_to_serial().
    • Benefit: Prevents unnecessary calls to the underlying hardware
      drivers when there is no data to transmit.
### Testing Performed:
    - Verified stable UART re-initialization after settings changes.
    - Verified system stability under high data load (parameter downloads in
      QGroundControl).

H3rR1s3MyD3m1s3 and others added 2 commits February 24, 2026 15:13
- Added NULL checks for malloc in ESP-NOW and BLE data transmission to prevent crashes under memory pressure.
- Added bounds check in handle_internal_telemetry to prevent buffer over-reads.
- Added uart_is_driver_installed() check to prevent redundant driver installations and resource leaks.
- Added zero-length check in write_to_serial() to optimize driver calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants