]> granicus.if.org Git - esp-idf/commitdiff
ble_mesh: fix ble mesh btc may caused memory leak
authorlly <lly@espressif.com>
Mon, 2 Sep 2019 07:39:59 +0000 (15:39 +0800)
committerlly <lly@espressif.com>
Mon, 9 Sep 2019 09:15:16 +0000 (17:15 +0800)
components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c
components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c
components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c
components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c
components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c
components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c

index 7d4d865b3fe82bcb2360dd64b6547620497ded37..fe2700e20a682b2ce2fae33bb2cb802c1c3f5d34 100644 (file)
@@ -126,6 +126,16 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
         return;
     }
 
+    if (p_src_data->params) {
+        p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
+        if (!p_dest_data->params) {
+            LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
+            return;
+        }
+
+        memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
+    }
+
     switch (msg->act) {
     case ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT:
     case ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT:
@@ -211,14 +221,6 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
             }
         }
     case ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT:
-        if (p_src_data->params) {
-            p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
-            if (p_dest_data->params) {
-                memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
-            } else {
-                LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
-            }
-        }
         break;
     default:
         break;
index f13b86bb6f8b79109cfdb2512ea751d63f28b8ec..a33ad6fca14d8d46d0bedaedd61cd936d559839f 100644 (file)
@@ -165,6 +165,16 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
         return;
     }
 
+    if (p_src_data->params) {
+        p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
+        if (!p_dest_data->params) {
+            LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
+            return;
+        }
+
+        memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
+    }
+
     switch (msg->act) {
     case ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT:
     case ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT:
@@ -277,14 +287,6 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
             }
         }
     case ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT:
-        if (p_src_data->params) {
-            p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
-            if (p_dest_data->params) {
-                memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
-            } else {
-                LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
-            }
-        }
         break;
     default:
         break;
index 5e1e01e958a7e807dce9eaaecb141118097e575b..c728f135eef6701231488c36a9698d84502529b5 100644 (file)
@@ -127,6 +127,16 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
         return;
     }
 
+    if (p_src_data->params) {
+        p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
+        if (!p_dest_data->params) {
+            LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
+            return;
+        }
+
+        memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
+    }
+
     switch (msg->act) {
     case ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT:
     case ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT:
@@ -167,14 +177,6 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
             }
         }
     case ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT:
-        if (p_src_data->params) {
-            p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
-            if (p_dest_data->params) {
-                memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
-            } else {
-                LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
-            }
-        }
         break;
     default:
         break;
index fdb5d2e49aac8691a181205bbaf9c86ceb041e69..9d75fbd976bd082e9ec081a50467816c2d836d8a 100644 (file)
@@ -121,6 +121,16 @@ static void btc_ble_mesh_lighting_client_copy_req_data(btc_msg_t *msg, void *p_d
         return;
     }
 
+    if (p_src_data->params) {
+        p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
+        if (!p_dest_data->params) {
+            LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
+            return;
+        }
+
+        memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
+    }
+
     switch (msg->act) {
     case ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT:
     case ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT:
@@ -147,14 +157,6 @@ static void btc_ble_mesh_lighting_client_copy_req_data(btc_msg_t *msg, void *p_d
             }
         }
     case ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT:
-        if (p_src_data->params) {
-            p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
-            if (p_dest_data->params) {
-                memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
-            } else {
-                LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
-            }
-        }
         break;
     default:
         break;
index f3766f1d46a675b309f438a3e93a5e4b6d37a09e..da03d540fe36dddfbf9e3873e9c2125353bcdd60 100644 (file)
@@ -256,6 +256,16 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
         return;
     }
 
+    if (p_src_data->params) {
+        p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
+        if (!p_dest_data->params) {
+            LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
+            return;
+        }
+
+        memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
+    }
+
     switch (msg->act) {
     case ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT:
     case ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT:
@@ -367,14 +377,6 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
             }
         }
     case ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT:
-        if (p_src_data->params) {
-            p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
-            if (p_dest_data->params) {
-                memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
-            } else {
-                LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
-            }
-        }
         break;
     default:
         break;
index c87b67237a345339ec5e84b158879793471594b3..7e29d2ea14dc36e136b916f7429a8f26e5036bcf 100644 (file)
@@ -121,6 +121,16 @@ static void btc_ble_mesh_time_scene_client_copy_req_data(btc_msg_t *msg, void *p
         return;
     }
 
+    if (p_src_data->params) {
+        p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
+        if (!p_dest_data->params) {
+            LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
+            return;
+        }
+
+        memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
+    }
+
     switch (msg->act) {
     case ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT:
     case ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT:
@@ -148,14 +158,6 @@ static void btc_ble_mesh_time_scene_client_copy_req_data(btc_msg_t *msg, void *p
             }
         }
     case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
-        if (p_src_data->params) {
-            p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
-            if (p_dest_data->params) {
-                memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
-            } else {
-                LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
-            }
-        }
         break;
     default:
         break;