]> granicus.if.org Git - esp-idf/commitdiff
Component/bt: fix blufi prepare write crash
authorzhiweijian <zhiweijian@espressif.com>
Mon, 25 Feb 2019 06:48:46 +0000 (14:48 +0800)
committerzhiweijian <zhiweijian@espressif.com>
Wed, 20 Mar 2019 06:23:11 +0000 (14:23 +0800)
components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c

index 873b5ed843f74adb2d024fc6ee664b3c6676933e..45c220b3ba4d7d9bb7b2642cab578c6942f8e888 100644 (file)
@@ -170,6 +170,14 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
             BTA_GATTS_SendRsp(p_data->req_data.conn_id, p_data->req_data.trans_id,
                           status, &rsp);
 
+            if(status != GATT_SUCCESS) {
+                if (blufi_env.prepare_buf) {
+                    osi_free(blufi_env.prepare_buf);
+                    blufi_env.prepare_buf = NULL;
+                }
+                BLUFI_TRACE_ERROR("write data error , error code 0x%x\n", status);
+                return;
+            }
             memcpy(blufi_env.prepare_buf + p_data->req_data.p_data->write_req.offset,
                    p_data->req_data.p_data->write_req.value,
                    p_data->req_data.p_data->write_req.len);
@@ -194,7 +202,7 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
         BTA_GATTS_SendRsp(p_data->req_data.conn_id, p_data->req_data.trans_id,
                     GATT_SUCCESS, NULL);
 
-        if (p_data->req_data.p_data->exec_write == GATT_PREP_WRITE_EXEC) {
+        if (blufi_env.prepare_buf && p_data->req_data.p_data->exec_write == GATT_PREP_WRITE_EXEC) {
             btc_blufi_recv_handler(blufi_env.prepare_buf, blufi_env.prepare_len);
         }