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

Commit 06497da6 authored by Jack He's avatar Jack He
Browse files

GD-Shim: Free BT_HDR after use or callback failure

* Legacy stack always assume the last user of BT_HDR
  will free the structure. Make sure we do this in GD
  shim as well

Bug: 185083624
Tag: #gd-refactor
Test: gd/cert/run

Send a 31MB video
- before this change, RSS increased by 86 MB when 10% (3MB) was sent
- after this change, RSS increased by 37 MB and stabilized, this
  increase is anticipated as the file needs to be cached in RAM

BYPASS_LONG_LINES_REASON: consist with gd format

Change-Id: Ie934e6d4edd7dfc79b4444ce1c13819834f59692
parent 971d6998
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -61,6 +61,6 @@ void bluetooth::shim::ACL_Disconnect(uint16_t handle, bool is_classic,
  mock_function_count_map[__func__]++;
}
void bluetooth::shim::ACL_Shutdown() { mock_function_count_map[__func__]++; }
void bluetooth::shim::ACL_WriteData(uint16_t handle, const BT_HDR* p_buf) {
void bluetooth::shim::ACL_WriteData(uint16_t handle, BT_HDR* p_buf) {
  mock_function_count_map[__func__]++;
}
+8 −1
Original line number Diff line number Diff line
@@ -299,7 +299,14 @@ class ShimAclConnection {
    BT_HDR* p_buf = MakeLegacyBtHdrPacket(std::move(packet), preamble);
    ASSERT_LOG(p_buf != nullptr,
               "Unable to allocate BT_HDR legacy packet handle:%04x", handle_);
    TRY_POSTING_ON_MAIN(send_data_upwards_, p_buf);
    if (send_data_upwards_ == nullptr) {
      LOG_WARN("Dropping ACL data with no callback");
      osi_free(p_buf);
    } else if (do_in_main_thread(FROM_HERE,
                                 base::Bind(send_data_upwards_, p_buf)) !=
               BT_STATUS_SUCCESS) {
      osi_free(p_buf);
    }
  }

  virtual void InitiateDisconnect(hci::DisconnectReason reason) = 0;
+2 −1
Original line number Diff line number Diff line
@@ -54,11 +54,12 @@ void bluetooth::shim::ACL_IgnoreLeConnectionFrom(
      ToAddressWithTypeFromLegacy(legacy_address_with_type));
}

void bluetooth::shim::ACL_WriteData(uint16_t handle, const BT_HDR* p_buf) {
void bluetooth::shim::ACL_WriteData(uint16_t handle, BT_HDR* p_buf) {
  std::unique_ptr<bluetooth::packet::RawBuilder> packet =
      MakeUniquePacket(p_buf->data + p_buf->offset + HCI_DATA_PREAMBLE_SIZE,
                       p_buf->len - HCI_DATA_PREAMBLE_SIZE);
  Stack::GetInstance()->GetAcl()->WriteData(handle, std::move(packet));
  osi_free(p_buf);
}

void bluetooth::shim::ACL_ConfigureLePrivacy(bool is_le_privacy_enabled) {
+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ bool ACL_AcceptLeConnectionFrom(const tBLE_BD_ADDR& legacy_address_with_type);
void ACL_IgnoreLeConnectionFrom(const tBLE_BD_ADDR& legacy_address_with_type);

void ACL_Disconnect(uint16_t handle, bool is_classic, tHCI_STATUS reason);
void ACL_WriteData(uint16_t handle, const BT_HDR* p_buf);
void ACL_WriteData(uint16_t handle, BT_HDR* p_buf);
void ACL_ConfigureLePrivacy(bool is_le_privacy_enabled);
void ACL_Shutdown();
void ACL_IgnoreAllLeConnections();
+1 −0
Original line number Diff line number Diff line
@@ -877,6 +877,7 @@ tBTM_STATUS bluetooth::shim::BTM_ClearInqDb(const RawAddress* p_bda) {
tBTM_STATUS bluetooth::shim::BTM_WriteEIR(BT_HDR* p_buff) {
  LOG_INFO("UNIMPLEMENTED %s", __func__);
  CHECK(p_buff != nullptr);
  osi_free(p_buff);
  return BTM_NO_RESOURCES;
}

Loading