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

Commit 6b0b42f3 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov Committed by Andre Eisenbach
Browse files

Replace malloc/calloc/free with osi_malloc/osi_calloc/osi_free

There were several leftover places that were still using
malloc/calloc/free .
Those are replaced to use osi_malloc/osi_calloc/osi_free like
majority of the rest of the code.

Note: There are few remaining places that are still using
malloc/calloc/free:
 * Some of the unit tests
 * audio_a2dp_hw/audio_a2dp_hw.c
   It is used as part of the audio.a2dp.default.so library,
   and the bluetooth.default.so library
   Its usage of malloc/calloc/free should be refactored
   independently.

Change-Id: Iafbed996e5f1ae8eb1343fb2acfadf32e515e419
parent e14ece7d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -201,7 +201,7 @@ void GKI_init_q (BUFFER_Q *p_q)
*******************************************************************************/
void *GKI_getbuf (UINT16 size)
{
  BUFFER_HDR_T *header = malloc(size + BUFFER_HDR_SIZE);
  BUFFER_HDR_T *header = osi_malloc(size + BUFFER_HDR_SIZE);
  header->status  = BUF_STATUS_UNLINKED;
  header->p_next  = NULL;
  header->Type    = 0;
@@ -243,7 +243,7 @@ void *GKI_getpoolbuf (UINT8 pool_id)
*******************************************************************************/
void GKI_freebuf (void *p_buf)
{
  free((BUFFER_HDR_T *)p_buf - 1);
  osi_free((BUFFER_HDR_T *)p_buf - 1);
}


+3 −3
Original line number Diff line number Diff line
@@ -657,7 +657,7 @@ void bta_av_rc_vendor_rsp(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
void bta_av_rc_meta_rsp(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
{
    tBTA_AV_RCB *p_rcb;
    BOOLEAN         free = TRUE;
    BOOLEAN         do_free = TRUE;

    if ((p_cb->features & BTA_AV_FEAT_METADATA) && (p_data->hdr.layer_specific < BTA_AV_NUM_RCB))
    {
@@ -669,12 +669,12 @@ void bta_av_rc_meta_rsp(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
                AVRC_MsgReq(p_rcb->handle, p_data->api_meta_rsp.label,
                            p_data->api_meta_rsp.rsp_code,
                            p_data->api_meta_rsp.p_pkt);
                free = FALSE;
                do_free = FALSE;
            }
        }
    }

    if (free)
    if (do_free)
        GKI_freebuf (p_data->api_meta_rsp.p_pkt);
}

+5 −4
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <pthread.h>
#include <stdlib.h>

#include "osi/include/allocator.h"
#include "bt_types.h"
#include "gki.h"
#include "utl.h"
@@ -2336,14 +2337,14 @@ static struct fc_channel *fcchan_get(uint16_t chan, char create)
    else if (!create)
        return NULL; /* we cannot alloc a struct if not asked to */

    t = calloc(sizeof(*t), 1);
    t = osi_calloc(sizeof(*t));
    if (!t)
        return NULL;

    t->chan = chan;

    if (!L2CA_RegisterFixedChannel(chan, &fcr)) {
        free(t);
        osi_free(t);
        return NULL;
    }

@@ -2402,7 +2403,7 @@ static struct fc_client *fcclient_alloc(uint16_t chan, char server, const uint8_
    else
        sec_id = bta_jv_alloc_sec_id();

    t = calloc(sizeof(*t), 1);
    t = osi_calloc(sizeof(*t));
    if (t) {
        //allocate it a unique ID
        do {
@@ -2470,7 +2471,7 @@ static void fcclient_free(struct fc_client *fc)
    //free security id
    bta_jv_free_sec_id(&fc->sec_id);

    free(fc);
    osi_free(fc);
}

static void fcchan_conn_chng_cbk(UINT16 chan, BD_ADDR bd_addr, BOOLEAN connected, UINT16 reason, tBT_TRANSPORT transport)
+3 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>

#include "osi/include/allocator.h"
#include "bt_types.h"
#include "gki.h"
#include "utl.h"
@@ -451,7 +452,7 @@ static void bta_sdp_search_cback(UINT16 result, void * user_data)
    evt_data.status = status;

    bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, (tBTA_SDP*) &evt_data, (void*)&uuid->uu.uuid128);
    free(user_data); // We no longer need the user data to track the search
    osi_free(user_data); // We no longer need the user data to track the search
}

/*******************************************************************************
@@ -484,7 +485,7 @@ void bta_sdp_search(tBTA_SDP_MSG *p_data)
{
    int x=0;
    // TODO: Leaks!!! but needed as user-data pointer
    tBT_UUID *bta_sdp_search_uuid = malloc(sizeof(tBT_UUID));
    tBT_UUID *bta_sdp_search_uuid = osi_malloc(sizeof(tBT_UUID));
    if(p_data == NULL)
    {
        APPL_TRACE_DEBUG("SDP control block handle is null");
+3 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <string.h>

#include "osi/include/alarm.h"
#include "osi/include/allocator.h"
#include "btcore/include/bdaddr.h"
#include "btif_config.h"
#include "btif_config_transcode.h"
@@ -290,7 +291,7 @@ bool btif_config_set_bin(const char *section, const char *key, const uint8_t *va
  if (length > 0)
      assert(value != NULL);

  char *str = (char *)calloc(length * 2 + 1, 1);
  char *str = (char *)osi_calloc(length * 2 + 1);
  if (!str)
    return false;

@@ -303,7 +304,7 @@ bool btif_config_set_bin(const char *section, const char *key, const uint8_t *va
  config_set_string(config, section, key, str);
  pthread_mutex_unlock(&lock);

  free(str);
  osi_free(str);
  return true;
}

Loading