Files
PX4-Autopilot/platforms
pkwr-air 824dd4c75a fix(USB): prevent hardfault on unplugging [v1.18] (#29187)
* fix(cdcacm_autostart): wait for mavlink stop before serdis on USB unplug

  On VBUS loss, 'mavlink stop' was spawned and serdis called on the next
  cycle without waiting for the stop to finish. serdis could then tear
  down the CDC/ACM driver while mavlink still had /dev/ttyACM0 open,
  causing a use-after-free in the driver (hardfault in cdcacm_recvpacket).

  Keep the pid of the stop task and only run serdis once it has exited
  (polled with kill(pid, 0), up to 5 s). waitpid() is not used because
  CONFIG_SCHED_WAITPID is not enabled on all boards. Also log
  exec_builtin() failures.

* fix(mavlink): close log files in the receiver thread

  The log handler opens the log file in the receiver thread, but on
  'mavlink stop' its destructor ran in the stop task and fclose()d it
  there. On NuttX a FILE belongs to the task group that opened it:
  fclose() from another task frees it while it stays linked in the
  owner's stream list, and the owner frees it again on exit. This double
  free corrupted the heap when USB was unplugged during a log download
  (hardfault in mm_free, or load_mon hanging in mallinfo()).

  Close the files at the end of MavlinkReceiver::run(), in the owning
  thread.

* fix(nuttx): update submodule with CDC/ACM use-after-free fix

  - drivers/serial,usbdev/cdcacm: free cdcacm device on last close
    (adapted from apache/nuttx#12199)
  - drivers/usbdev/cdcacm: flush rxpending on reset and harden paths
    after unbind
2026-11-17 10:38:54 +13:00
..
…
…