mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
[Sponsored by CubePilot] Try to fix potential mavlink segfaults on USB disconnect (#26083)
* mavlink: fix potential use-after-free If a mavlink instance is force stopped, the main thread might be out of scope and the receiver thread would be doing a use-after-free. Instead the receiver thread needs to check its own _should_exit flag. * mavlink: protect shared data by mutex in dtor I'm not sure if this potentially fixes any of the segfaults we have seen on stopping mavlink instances but it potentially could matter if the mavlink_receiver thread is killed after a timeout and tries to send any messages as a zombie.
This commit is contained in:
parent
b92d21bd31
commit
5fe82aa485
@ -163,7 +163,10 @@ Mavlink::~Mavlink()
|
||||
}
|
||||
|
||||
if (_instance_id >= 0) {
|
||||
mavlink_module_instances[_instance_id] = nullptr;
|
||||
{
|
||||
LockGuard lg{mavlink_module_mutex};
|
||||
mavlink_module_instances[_instance_id] = nullptr;
|
||||
}
|
||||
mavlink_instance_count.fetch_sub(1);
|
||||
}
|
||||
|
||||
|
||||
@ -3160,7 +3160,7 @@ MavlinkReceiver::run()
|
||||
ssize_t nread = 0;
|
||||
hrt_abstime last_send_update = 0;
|
||||
|
||||
while (!_mavlink.should_exit()) {
|
||||
while (!_should_exit.load()) {
|
||||
|
||||
// check for parameter updates
|
||||
if (_parameter_update_sub.updated()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user