diff options
author | 2024-11-14 18:16:20 +0000 | |
---|---|---|
committer | 2024-11-14 18:16:20 +0000 | |
commit | 7045fa1c2940f82c75f29aaecf8185d0b39ede9c (patch) | |
tree | 677d11dd65a2a445008bae15db37f125dee3636a | |
parent | 231e391f9b9f8913adcecc3c551b97ae86054479 (diff) | |
parent | b15a07512763cb108eb6c6516d83ea68d4eb8e94 (diff) |
Merge "topshim: a2dp: Avoid leaking the reference of a stack object" into main
-rw-r--r-- | system/gd/rust/topshim/btav/btav_shim.cc | 11 | ||||
-rw-r--r-- | system/gd/rust/topshim/btav_sink/btav_sink_shim.cc | 11 |
2 files changed, 8 insertions, 14 deletions
diff --git a/system/gd/rust/topshim/btav/btav_shim.cc b/system/gd/rust/topshim/btav/btav_shim.cc index 3838d03b66..eed0d54190 100644 --- a/system/gd/rust/topshim/btav/btav_shim.cc +++ b/system/gd/rust/topshim/btav/btav_shim.cc @@ -239,18 +239,15 @@ static ::rust::Vec<A2dpCodecConfig> to_rust_codec_config_vec( return rconfigs; } -static A2dpError to_rust_error(const btav_error_t& error) { +static void connection_state_cb(const RawAddress& addr, btav_connection_state_t state, + const btav_error_t& error) { + // CAUTION: The error_msg field is a reference and could refer to a rvalue on the stack. + // DO NOT make this conversion into a helper function. A2dpError a2dp_error = { .status = error.status, .error_code = error.error_code, .error_msg = error.error_msg.value_or(""), }; - return a2dp_error; -} - -static void connection_state_cb(const RawAddress& addr, btav_connection_state_t state, - const btav_error_t& error) { - A2dpError a2dp_error = to_rust_error(error); rusty::connection_state_callback(addr, state, a2dp_error); } static void audio_state_cb(const RawAddress& addr, btav_audio_state_t state) { diff --git a/system/gd/rust/topshim/btav_sink/btav_sink_shim.cc b/system/gd/rust/topshim/btav_sink/btav_sink_shim.cc index 8b38b9b15a..d2999d9a2c 100644 --- a/system/gd/rust/topshim/btav_sink/btav_sink_shim.cc +++ b/system/gd/rust/topshim/btav_sink/btav_sink_shim.cc @@ -32,18 +32,15 @@ namespace rust { namespace internal { static A2dpSinkIntf* g_a2dp_sink_if; -static A2dpError to_rust_error(const btav_error_t& error) { +static void connection_state_cb(const RawAddress& addr, btav_connection_state_t state, + const btav_error_t& error) { + // CAUTION: The error_msg field is a reference and could refer to a rvalue on the stack. + // DO NOT make this conversion into a helper function. A2dpError a2dp_error = { .status = error.status, .error_code = error.error_code, .error_msg = error.error_msg.value_or(""), }; - return a2dp_error; -} - -static void connection_state_cb(const RawAddress& addr, btav_connection_state_t state, - const btav_error_t& error) { - A2dpError a2dp_error = to_rust_error(error); rusty::sink_connection_state_callback(addr, state, a2dp_error); } static void audio_state_cb(const RawAddress& addr, btav_audio_state_t state) { |