Skip to content

Commit 2dc1a9b

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'bugfix/fix_hid_memory_leak_v5.5' into 'release/v5.5'
fix(bt/bluedroid): Fixed HID memory leak (v5.5) See merge request espressif/esp-idf!43331
2 parents 39bcc8f + 38ea935 commit 2dc1a9b

File tree

9 files changed

+17
-16
lines changed

9 files changed

+17
-16
lines changed

components/bt/common/osi/allocator.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,5 @@ void *osi_calloc_func(size_t size)
241241

242242
void osi_free_func(void *ptr)
243243
{
244-
#if HEAP_MEMORY_DEBUG
245-
osi_mem_dbg_clean(ptr, __func__, __LINE__);
246-
#endif
247-
free(ptr);
244+
osi_free(ptr);
248245
}

components/bt/host/bluedroid/api/esp_hidd_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ esp_err_t esp_bt_hid_device_send_report(esp_hidd_report_type_t type, uint8_t id,
133133
args.send_report.data = data;
134134

135135
bt_status_t stat = btc_transfer_context(&msg, &args, sizeof(btc_hidd_args_t),
136-
btc_hd_arg_deep_copy, btc_hd_cb_arg_deep_free);
136+
btc_hd_arg_deep_copy, btc_hd_call_arg_deep_free);
137137
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
138138
}
139139

components/bt/host/bluedroid/api/esp_hidh_api.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
117117
arg.set_info.hid_info = hid_info;
118118

119119
bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hidh_args_t),
120-
btc_hh_arg_deep_copy, btc_hh_cb_arg_deep_free);
120+
btc_hh_arg_deep_copy, btc_hh_call_arg_deep_free);
121121
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
122122
}
123123

@@ -224,7 +224,7 @@ esp_err_t esp_bt_hid_host_set_report(esp_bd_addr_t bd_addr, esp_hidh_report_type
224224
arg.set_report.report = report;
225225

226226
bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hidh_args_t),
227-
btc_hh_arg_deep_copy, btc_hh_cb_arg_deep_free);
227+
btc_hh_arg_deep_copy, btc_hh_call_arg_deep_free);
228228
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
229229
}
230230

@@ -243,7 +243,7 @@ esp_err_t esp_bt_hid_host_send_data(esp_bd_addr_t bd_addr, uint8_t *data, size_t
243243
arg.send_data.data = data;
244244

245245
bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hidh_args_t),
246-
btc_hh_arg_deep_copy, btc_hh_cb_arg_deep_free);
246+
btc_hh_arg_deep_copy, btc_hh_call_arg_deep_free);
247247
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
248248
}
249249

components/bt/host/bluedroid/btc/profile/std/hid/btc_hd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ btc_hd_cb_t btc_hd_cb = {0};
7575

7676
typedef void (bt_hid_copy_cb_t)(btc_msg_t *msg, void *p_dest, void *p_src);
7777

78+
static void btc_hd_cb_arg_deep_free(btc_msg_t *msg);
79+
7880
static inline void btc_hd_cb_to_app(esp_hidd_cb_event_t event, esp_hidd_cb_param_t *param)
7981
{
8082
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)
705707
}
706708
}
707709

708-
static void btc_hd_call_arg_deep_free(btc_msg_t *msg)
710+
void btc_hd_call_arg_deep_free(btc_msg_t *msg)
709711
{
710712
btc_hidd_args_t *arg = (btc_hidd_args_t *)msg->arg;
711713

@@ -756,7 +758,7 @@ void btc_hd_call_handler(btc_msg_t *msg)
756758
btc_hd_call_arg_deep_free(msg);
757759
}
758760

759-
void btc_hd_cb_arg_deep_free(btc_msg_t *msg)
761+
static void btc_hd_cb_arg_deep_free(btc_msg_t *msg)
760762
{
761763
tBTA_HD *arg = (tBTA_HD *)msg->arg;
762764

components/bt/host/bluedroid/btc/profile/std/hid/btc_hh.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ static bdstr_t bdstr;
6464
#define is_hidh_init() (btc_hh_cb.status > BTC_HH_DISABLED)
6565
#define BTC_TIMEOUT_VUP_MS (3 * 1000)
6666

67+
static void btc_hh_cb_arg_deep_free(btc_msg_t *msg);
68+
6769
static inline void btc_hh_cb_to_app(esp_hidh_cb_event_t event, esp_hidh_cb_param_t *param)
6870
{
6971
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)
10971099
}
10981100
}
10991101

1100-
static void btc_hh_call_arg_deep_free(btc_msg_t *msg)
1102+
void btc_hh_call_arg_deep_free(btc_msg_t *msg)
11011103
{
11021104
btc_hidh_args_t *arg = (btc_hidh_args_t *)msg->arg;
11031105

@@ -1166,7 +1168,7 @@ void btc_hh_call_handler(btc_msg_t *msg)
11661168
btc_hh_call_arg_deep_free(msg);
11671169
}
11681170

1169-
void btc_hh_cb_arg_deep_free(btc_msg_t *msg)
1171+
static void btc_hh_cb_arg_deep_free(btc_msg_t *msg)
11701172
{
11711173
tBTA_HH *arg = (tBTA_HH *)msg->arg;
11721174

components/bt/host/bluedroid/btc/profile/std/include/btc_hd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void btc_hd_call_handler(btc_msg_t *msg);
9999
void btc_hd_cb_handler(btc_msg_t *msg);
100100

101101
void btc_hd_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
102-
void btc_hd_cb_arg_deep_free(btc_msg_t *msg);
102+
void btc_hd_call_arg_deep_free(btc_msg_t *msg);
103103

104104
void btc_hd_get_profile_status(esp_hidd_profile_status_t *param);
105105

components/bt/host/bluedroid/btc/profile/std/include/btc_hh.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ void btc_hh_call_handler(btc_msg_t *msg);
181181
void btc_hh_cb_handler(btc_msg_t *msg);
182182

183183
void btc_hh_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
184-
185-
void btc_hh_cb_arg_deep_free(btc_msg_t *msg);
184+
void btc_hh_call_arg_deep_free(btc_msg_t *msg);
186185

187186
bool btc_hh_add_added_dev(BD_ADDR bd_addr, uint16_t attr_mask);
188187

components/bt/host/bluedroid/stack/hid/hidd_conn.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ tHID_STATUS hidd_conn_send_data(uint8_t channel, uint8_t msg_type, uint8_t param
775775
}
776776
return HID_SUCCESS;
777777
}
778+
osi_free(p_buf);
778779
return HID_ERR_NO_CONNECTION;
779780
}
780781
#ifdef REPORT_TRANSFER_TIMESTAMP

components/bt/host/bluedroid/stack/l2cap/l2c_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <stdlib.h>
2626
#include <string.h>
2727

28-
#include "osi/allocator.h"
2928
#include "device/controller.h"
3029
#include "stack/bt_types.h"
3130
#include "stack/hcimsgs.h"
@@ -36,6 +35,7 @@
3635
#include "stack/btm_api.h"
3736
#include "btm_int.h"
3837
#include "stack/hcidefs.h"
38+
#include "bt_common.h"
3939
#include "osi/allocator.h"
4040
#include "osi/list.h"
4141

0 commit comments

Comments
 (0)