fix(bt/bluedroid): Fixed HID memory leak

This commit is contained in:
liqigan
2025-10-23 18:08:59 +08:00
parent 245f5f7f43
commit 1b9419d7ca
9 changed files with 17 additions and 16 deletions

View File

@@ -241,8 +241,5 @@ void *osi_calloc_func(size_t size)
void osi_free_func(void *ptr)
{
#if HEAP_MEMORY_DEBUG
osi_mem_dbg_clean(ptr, __func__, __LINE__);
#endif
free(ptr);
osi_free(ptr);
}

View File

@@ -133,7 +133,7 @@ esp_err_t esp_bt_hid_device_send_report(esp_hidd_report_type_t type, uint8_t id,
args.send_report.data = data;
bt_status_t stat = btc_transfer_context(&msg, &args, sizeof(btc_hidd_args_t),
btc_hd_arg_deep_copy, btc_hd_cb_arg_deep_free);
btc_hd_arg_deep_copy, btc_hd_call_arg_deep_free);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

View File

@@ -117,7 +117,7 @@ esp_err_t esp_bt_hid_host_set_info(esp_bd_addr_t bd_addr, esp_hidh_hid_info_t *h
arg.set_info.hid_info = hid_info;
bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hidh_args_t),
btc_hh_arg_deep_copy, btc_hh_cb_arg_deep_free);
btc_hh_arg_deep_copy, btc_hh_call_arg_deep_free);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}
@@ -224,7 +224,7 @@ esp_err_t esp_bt_hid_host_set_report(esp_bd_addr_t bd_addr, esp_hidh_report_type
arg.set_report.report = report;
bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hidh_args_t),
btc_hh_arg_deep_copy, btc_hh_cb_arg_deep_free);
btc_hh_arg_deep_copy, btc_hh_call_arg_deep_free);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}
@@ -243,7 +243,7 @@ esp_err_t esp_bt_hid_host_send_data(esp_bd_addr_t bd_addr, uint8_t *data, size_t
arg.send_data.data = data;
bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hidh_args_t),
btc_hh_arg_deep_copy, btc_hh_cb_arg_deep_free);
btc_hh_arg_deep_copy, btc_hh_call_arg_deep_free);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

View File

@@ -75,6 +75,8 @@ btc_hd_cb_t btc_hd_cb = {0};
typedef void (bt_hid_copy_cb_t)(btc_msg_t *msg, void *p_dest, void *p_src);
static void btc_hd_cb_arg_deep_free(btc_msg_t *msg);
static inline void btc_hd_cb_to_app(esp_hidd_cb_event_t event, esp_hidd_cb_param_t *param)
{
esp_hd_cb_t btc_hd_cb = (esp_hd_cb_t)btc_profile_cb_get(BTC_PID_HD);
@@ -705,7 +707,7 @@ static void btc_hd_virtual_cable_unplug(void)
}
}
static void btc_hd_call_arg_deep_free(btc_msg_t *msg)
void btc_hd_call_arg_deep_free(btc_msg_t *msg)
{
btc_hidd_args_t *arg = (btc_hidd_args_t *)msg->arg;
@@ -756,7 +758,7 @@ void btc_hd_call_handler(btc_msg_t *msg)
btc_hd_call_arg_deep_free(msg);
}
void btc_hd_cb_arg_deep_free(btc_msg_t *msg)
static void btc_hd_cb_arg_deep_free(btc_msg_t *msg)
{
tBTA_HD *arg = (tBTA_HD *)msg->arg;

View File

@@ -64,6 +64,8 @@ static bdstr_t bdstr;
#define is_hidh_init() (btc_hh_cb.status > BTC_HH_DISABLED)
#define BTC_TIMEOUT_VUP_MS (3 * 1000)
static void btc_hh_cb_arg_deep_free(btc_msg_t *msg);
static inline void btc_hh_cb_to_app(esp_hidh_cb_event_t event, esp_hidh_cb_param_t *param)
{
esp_hh_cb_t btc_hh_cb = (esp_hh_cb_t)btc_profile_cb_get(BTC_PID_HH);
@@ -1097,7 +1099,7 @@ static void btc_hh_set_idle_time(btc_hidh_args_t *arg)
}
}
static void btc_hh_call_arg_deep_free(btc_msg_t *msg)
void btc_hh_call_arg_deep_free(btc_msg_t *msg)
{
btc_hidh_args_t *arg = (btc_hidh_args_t *)msg->arg;
@@ -1166,7 +1168,7 @@ void btc_hh_call_handler(btc_msg_t *msg)
btc_hh_call_arg_deep_free(msg);
}
void btc_hh_cb_arg_deep_free(btc_msg_t *msg)
static void btc_hh_cb_arg_deep_free(btc_msg_t *msg)
{
tBTA_HH *arg = (tBTA_HH *)msg->arg;

View File

@@ -99,7 +99,7 @@ void btc_hd_call_handler(btc_msg_t *msg);
void btc_hd_cb_handler(btc_msg_t *msg);
void btc_hd_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_hd_cb_arg_deep_free(btc_msg_t *msg);
void btc_hd_call_arg_deep_free(btc_msg_t *msg);
void btc_hd_get_profile_status(esp_hidd_profile_status_t *param);

View File

@@ -181,8 +181,7 @@ void btc_hh_call_handler(btc_msg_t *msg);
void btc_hh_cb_handler(btc_msg_t *msg);
void btc_hh_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_hh_cb_arg_deep_free(btc_msg_t *msg);
void btc_hh_call_arg_deep_free(btc_msg_t *msg);
bool btc_hh_add_added_dev(BD_ADDR bd_addr, uint16_t attr_mask);

View File

@@ -775,6 +775,7 @@ tHID_STATUS hidd_conn_send_data(uint8_t channel, uint8_t msg_type, uint8_t param
}
return HID_SUCCESS;
}
osi_free(p_buf);
return HID_ERR_NO_CONNECTION;
}
#ifdef REPORT_TRANSFER_TIMESTAMP

View File

@@ -25,7 +25,6 @@
#include <stdlib.h>
#include <string.h>
#include "osi/allocator.h"
#include "device/controller.h"
#include "stack/bt_types.h"
#include "stack/hcimsgs.h"
@@ -36,6 +35,7 @@
#include "stack/btm_api.h"
#include "btm_int.h"
#include "stack/hcidefs.h"
#include "bt_common.h"
#include "osi/allocator.h"
#include "osi/list.h"