From b3bd5cbf77ed612ad6bc5437bfa8e8b49262f938 Mon Sep 17 00:00:00 2001 From: chenjianhua Date: Thu, 11 Aug 2022 19:41:35 +0800 Subject: [PATCH] fix esp hid crash when auth failed --- components/esp_hid/src/ble_hidh.c | 2 ++ components/esp_hid/src/esp_hidh.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/esp_hid/src/ble_hidh.c b/components/esp_hid/src/ble_hidh.c index 5fe54f2fa7..9563d3a0b7 100644 --- a/components/esp_hid/src/ble_hidh.c +++ b/components/esp_hid/src/ble_hidh.c @@ -112,6 +112,8 @@ static void read_device_services(esp_gatt_if_t gattc_if, esp_hidh_dev_t *dev) ESP_LOGE(TAG, "malloc report maps failed"); return; } + /* read characteristic value may failed, so we should init report maps */ + memset(dev->config.report_maps, 0, dev->config.report_maps_len * sizeof(esp_hid_raw_report_map_t)); for (uint16_t s = 0; s < dcount; s++) { suuid = service_result[s].uuid.uuid.uuid16; diff --git a/components/esp_hid/src/esp_hidh.c b/components/esp_hid/src/esp_hidh.c index 8bc38165c6..d7d93e5b20 100644 --- a/components/esp_hid/src/esp_hidh.c +++ b/components/esp_hid/src/esp_hidh.c @@ -370,7 +370,10 @@ static void esp_hidh_dev_resources_free(esp_hidh_dev_t *dev) free((void *)dev->config.manufacturer_name); free((void *)dev->config.serial_number); for (uint8_t d = 0; d < dev->config.report_maps_len; d++) { - free((void *)dev->config.report_maps[d].data); + /* data of report map maybe is NULL */ + if (dev->config.report_maps[d].data) { + free((void *)dev->config.report_maps[d].data); + } } free((void *)dev->config.report_maps); esp_hidh_dev_report_t *r;