Browse Source

fix racey `if (weak_ptr.expired()) {...weak_ptr.lock()...}`

QGC4.4
Keith Bennett 4 years ago committed by Don Gagne
parent
commit
33e8a15d36
  1. 29
      src/Vehicle/InitialConnectStateMachine.cc

29
src/Vehicle/InitialConnectStateMachine.cc

@ -95,10 +95,9 @@ void InitialConnectStateMachine::_stateRequestCapabilities(StateMachine* stateMa @@ -95,10 +95,9 @@ void InitialConnectStateMachine::_stateRequestCapabilities(StateMachine* stateMa
{
InitialConnectStateMachine* connectMachine = static_cast<InitialConnectStateMachine*>(stateMachine);
Vehicle* vehicle = connectMachine->_vehicle;
WeakLinkInterfacePtr weakLink = vehicle->vehicleLinkManager()->primaryLink();
SharedLinkInterfacePtr sharedLink = vehicle->vehicleLinkManager()->primaryLink().lock();
SharedLinkInterfacePtr sharedLink = weakLink.lock();
if (weakLink.expired()) {
if (!sharedLink) {
qCDebug(InitialConnectStateMachineLog) << "_stateRequestCapabilities Skipping capability request due to no primary link";
connectMachine->advance();
} else {
@ -206,14 +205,12 @@ void InitialConnectStateMachine::_stateRequestProtocolVersion(StateMachine* stat @@ -206,14 +205,12 @@ void InitialConnectStateMachine::_stateRequestProtocolVersion(StateMachine* stat
{
InitialConnectStateMachine* connectMachine = static_cast<InitialConnectStateMachine*>(stateMachine);
Vehicle* vehicle = connectMachine->_vehicle;
WeakLinkInterfacePtr weakLink = vehicle->vehicleLinkManager()->primaryLink();
SharedLinkInterfacePtr sharedLink = vehicle->vehicleLinkManager()->primaryLink().lock();
if (weakLink.expired()) {
if (!sharedLink) {
qCDebug(InitialConnectStateMachineLog) << "_stateRequestProtocolVersion Skipping protocol version request due to no primary link";
connectMachine->advance();
} else {
SharedLinkInterfacePtr sharedLink = weakLink.lock();
if (sharedLink->linkConfiguration()->isHighLatency() || sharedLink->isPX4Flow() || sharedLink->isLogReplay()) {
qCDebug(InitialConnectStateMachineLog) << "_stateRequestProtocolVersion Skipping protocol version request due to link type";
connectMachine->advance();
@ -316,17 +313,15 @@ void InitialConnectStateMachine::_stateRequestMission(StateMachine* stateMachine @@ -316,17 +313,15 @@ void InitialConnectStateMachine::_stateRequestMission(StateMachine* stateMachine
{
InitialConnectStateMachine* connectMachine = static_cast<InitialConnectStateMachine*>(stateMachine);
Vehicle* vehicle = connectMachine->_vehicle;
WeakLinkInterfacePtr weakLink = vehicle->vehicleLinkManager()->primaryLink();
SharedLinkInterfacePtr sharedLink = vehicle->vehicleLinkManager()->primaryLink().lock();
disconnect(vehicle->_parameterManager, &ParameterManager::loadProgressChanged, connectMachine,
&InitialConnectStateMachine::gotProgressUpdate);
if (weakLink.expired()) {
if (!sharedLink) {
qCDebug(InitialConnectStateMachineLog) << "_stateRequestMission: Skipping first mission load request due to no primary link";
connectMachine->advance();
} else {
SharedLinkInterfacePtr sharedLink = weakLink.lock();
if (sharedLink->linkConfiguration()->isHighLatency() || sharedLink->isPX4Flow() || sharedLink->isLogReplay()) {
qCDebug(InitialConnectStateMachineLog) << "_stateRequestMission: Skipping first mission load request due to link type";
vehicle->_firstMissionLoadComplete();
@ -341,14 +336,12 @@ void InitialConnectStateMachine::_stateRequestGeoFence(StateMachine* stateMachin @@ -341,14 +336,12 @@ void InitialConnectStateMachine::_stateRequestGeoFence(StateMachine* stateMachin
{
InitialConnectStateMachine* connectMachine = static_cast<InitialConnectStateMachine*>(stateMachine);
Vehicle* vehicle = connectMachine->_vehicle;
WeakLinkInterfacePtr weakLink = vehicle->vehicleLinkManager()->primaryLink();
SharedLinkInterfacePtr sharedLink = vehicle->vehicleLinkManager()->primaryLink().lock();
if (weakLink.expired()) {
if (!sharedLink) {
qCDebug(InitialConnectStateMachineLog) << "_stateRequestGeoFence: Skipping first geofence load request due to no primary link";
connectMachine->advance();
} else {
SharedLinkInterfacePtr sharedLink = weakLink.lock();
if (sharedLink->linkConfiguration()->isHighLatency() || sharedLink->isPX4Flow() || sharedLink->isLogReplay()) {
qCDebug(InitialConnectStateMachineLog) << "_stateRequestGeoFence: Skipping first geofence load request due to link type";
vehicle->_firstGeoFenceLoadComplete();
@ -368,14 +361,12 @@ void InitialConnectStateMachine::_stateRequestRallyPoints(StateMachine* stateMac @@ -368,14 +361,12 @@ void InitialConnectStateMachine::_stateRequestRallyPoints(StateMachine* stateMac
{
InitialConnectStateMachine* connectMachine = static_cast<InitialConnectStateMachine*>(stateMachine);
Vehicle* vehicle = connectMachine->_vehicle;
WeakLinkInterfacePtr weakLink = vehicle->vehicleLinkManager()->primaryLink();
SharedLinkInterfacePtr sharedLink = vehicle->vehicleLinkManager()->primaryLink().lock();
if (weakLink.expired()) {
if (!sharedLink) {
qCDebug(InitialConnectStateMachineLog) << "_stateRequestRallyPoints: Skipping first rally point load request due to no primary link";
connectMachine->advance();
} else {
SharedLinkInterfacePtr sharedLink = weakLink.lock();
if (sharedLink->linkConfiguration()->isHighLatency() || sharedLink->isPX4Flow() || sharedLink->isLogReplay()) {
qCDebug(InitialConnectStateMachineLog) << "_stateRequestRallyPoints: Skipping first rally point load request due to link type";
vehicle->_firstRallyPointLoadComplete();

Loading…
Cancel
Save