Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8b71db87 authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Use weak pointers instead of base::Unretained to prevent use after free

Bug: 78517259
Test: Compile and switch users while AVRCP is connected
Change-Id: I9eb4482e4de52fed7750747afdc7cfb5402615a4
parent 58460da8
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -160,8 +160,9 @@ bool ConnectionHandler::SdpLookup(const RawAddress& bdaddr, SdpCallback cb) {

  return avrc_->FindService(
             UUID_SERVCLASS_AV_REMOTE_CONTROL, bdaddr, &db_params,
             base::Bind(&ConnectionHandler::SdpCb, base::Unretained(this),
                        bdaddr, cb, disc_db)) == AVRC_SUCCESS;
             base::Bind(&ConnectionHandler::SdpCb,
                        weak_ptr_factory_.GetWeakPtr(), bdaddr, cb, disc_db)) ==
         AVRC_SUCCESS;
}

bool ConnectionHandler::AvrcpConnect(bool initiator, const RawAddress& bdaddr) {
@@ -176,7 +177,7 @@ bool ConnectionHandler::AvrcpConnect(bool initiator, const RawAddress& bdaddr) {
                                    weak_ptr_factory_.GetWeakPtr());
  }
  open_cb.msg_cback =
      base::Bind(&ConnectionHandler::MessageCb, base::Unretained(this));
      base::Bind(&ConnectionHandler::MessageCb, weak_ptr_factory_.GetWeakPtr());
  open_cb.company_id = AVRC_CO_GOOGLE;
  open_cb.conn = initiator ? AVRC_CONN_INT
                           : AVRC_CONN_ACP;  // 0 if initiator, 1 if acceptor
@@ -286,7 +287,7 @@ void ConnectionHandler::AcceptorControlCb(uint8_t handle, uint8_t event,
      LOG(INFO) << __PRETTY_FUNCTION__ << ": Connection Opened Event";

      auto&& callback = base::Bind(&ConnectionHandler::SendMessage,
                                   base::Unretained(this), handle);
                                   weak_ptr_factory_.GetWeakPtr(), handle);
      auto&& ctrl_mtu = avrc_->GetPeerMtu(handle) - AVCT_HDR_LEN;
      auto&& browse_mtu = avrc_->GetBrowseMtu(handle) - AVCT_HDR_LEN;
      std::shared_ptr<Device> newDevice = std::make_shared<Device>(