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

Commit c1bbf2fa authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Fix a memory leak when disabling AVDTP

Added new function bta_av_free_scb() to explicitly
free tBTA_AV_SCB struct.

Bug: 78034873
Test: Code compilation
Change-Id: Ic738c64f61fd273bc2988fa98cb7cedebf1c4b76
Merged-In: Ic738c64f61fd273bc2988fa98cb7cedebf1c4b76
(cherry picked from commit b4bd9ee17e242be9a8707246e2e9346e66bc8b1f)
parent 1b2b9501
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -2075,9 +2075,7 @@ void bta_av_dereg_comp(tBTA_AV_DATA* p_data) {
#endif
    }

    /* make sure that the timer is not active */
    alarm_cancel(p_scb->avrc_ct_timer);
    osi_free_and_reset((void**)&p_cb->p_scb[p_scb->hdi]);
    bta_av_free_scb(p_scb);
  }

  APPL_TRACE_DEBUG("%s: audio 0x%x, disable:%d", __func__, p_cb->reg_audio,
+1 −0
Original line number Diff line number Diff line
@@ -640,6 +640,7 @@ extern bool bta_av_is_scb_init(tBTA_AV_SCB* p_scb);
extern void bta_av_set_scb_sst_incoming(tBTA_AV_SCB* p_scb);
extern tBTA_AV_LCB* bta_av_find_lcb(const RawAddress& addr, uint8_t op);
extern const char* bta_av_sst_code(uint8_t state);
extern void bta_av_free_scb(tBTA_AV_SCB* p_scb);

/* main functions */
extern void bta_av_api_deregister(tBTA_AV_DATA* p_data);
+11 −0
Original line number Diff line number Diff line
@@ -330,6 +330,17 @@ static tBTA_AV_SCB* bta_av_alloc_scb(tBTA_AV_CHNL chnl) {
  return nullptr;
}

void bta_av_free_scb(tBTA_AV_SCB* p_scb) {
  if (p_scb == nullptr) return;
  uint8_t scb_index = p_scb->hdi;
  CHECK(scb_index < BTA_AV_NUM_STRS);

  CHECK(p_scb == bta_av_cb.p_scb[scb_index]);
  bta_av_cb.p_scb[scb_index] = nullptr;
  alarm_free(p_scb->avrc_ct_timer);
  osi_free(p_scb);
}

/*******************************************************************************
 ******************************************************************************/
void bta_av_conn_cback(UNUSED_ATTR uint8_t handle, const RawAddress& bd_addr,