Skip to content

Commit

Permalink
uxrce_dds_client - Fix nullptr access in certain cleanup situations (#…
Browse files Browse the repository at this point in the history
…23913)

* Only close initialized objects

* Added err log in case of no ping

* Added err log in case of timesync timeout
  • Loading branch information
alexcekay authored Nov 11, 2024
1 parent 3e3151c commit fbbfcdb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/modules/uxrce_dds_client/uxrce_dds_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ bool UxrceddsClient::setup_session(uxrSession *session)
}

if (!got_response) {
PX4_ERR("got no ping from agent");
return false;
}

Expand All @@ -241,6 +242,8 @@ bool UxrceddsClient::setup_session(uxrSession *session)
return false;
}

_session_created = true;

// Streams
// Reliable for setup, afterwards best-effort to send the data (important: need to create all 4 streams)
_reliable_out = uxr_create_output_reliable_stream(session, _output_reliable_stream_buffer,
Expand Down Expand Up @@ -351,6 +354,7 @@ bool UxrceddsClient::setup_session(uxrSession *session)
}

if (sync_timeouts > TIMESYNC_MAX_TIMEOUTS) {
PX4_ERR("timeout during time synchronization");
return false;
}

Expand Down Expand Up @@ -378,10 +382,18 @@ bool UxrceddsClient::setup_session(uxrSession *session)
void UxrceddsClient::delete_session(uxrSession *session)
{
delete_repliers();
uxr_delete_session_retries(session, _connected ? 1 : 0);

if (_session_created) {
uxr_delete_session_retries(session, _connected ? 1 : 0);
_session_created = false;
}

if (_subs_initialized) {
_subs->reset();
_subs_initialized = false;
}

_last_payload_tx_rate = 0;
_subs->reset();
_timesync.reset_filter();
}

Expand Down Expand Up @@ -549,6 +561,7 @@ void UxrceddsClient::run()
int poll_error_counter = 0;

_subs->init();
_subs_initialized = true;

while (!should_exit() && _connected) {
perf_begin(_loop_perf);
Expand Down
4 changes: 3 additions & 1 deletion src/modules/uxrce_dds_client/uxrce_dds_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ class UxrceddsClient : public ModuleBase<UxrceddsClient>, public ModuleParams

int _last_payload_tx_rate{}; ///< in B/s
int _last_payload_rx_rate{}; ///< in B/s
bool _connected{false};

bool _connected{false};
bool _session_created{false};
bool _timesync_converged{false};
bool _subs_initialized{false};

Timesync _timesync{timesync_status_s::SOURCE_PROTOCOL_DDS};

Expand Down

0 comments on commit fbbfcdb

Please sign in to comment.