Przeglądaj źródła

1、修复4G websocket可能导致内存泄漏问题

liyuezong 1 rok temu
rodzic
commit
62e4d9cd39
1 zmienionych plików z 23 dodań i 18 usunięć
  1. 23 18
      pro/src/json_handle.c

+ 23 - 18
pro/src/json_handle.c

@@ -4648,11 +4648,13 @@ char* communication_4G_ack_to_json(CellInfo_t* _CellularManagerTemp,int nWSType)
     //创建数据
     memset(temp, 0, sizeof(temp));
 
-    cJSON* sdata_filed = cJSON_CreateObject();
+    cJSON* sdata_filed = NULL;
+
     // 创建数据
     cJSON *data_root_array = cJSON_CreateObject();
     if (nWSType)
     {
+        sdata_filed = cJSON_CreateObject();
         cJSON_AddNumberToObject(sdata_filed, "code", 200);
     }
     else
@@ -4689,30 +4691,32 @@ char* communication_4G_ack_to_json(CellInfo_t* _CellularManagerTemp,int nWSType)
     sprintf(temp, "%d dBm", _CellularManagerTemp->Signal_strength);
     cJSON_AddStringToObject(data_root_array, "xhqd", temp);
 
-    int idx=0;
-    cJSON* array=NULL;
-    for(int i=0; i<MAIL_RECV_MAX; i++) {
-        if(1) {
-            cJSON* tmp = cJSON_CreateObject();
-            if(strlen(_CellularManagerTemp->sms_recv[i].account)>0) {
-                cJSON_AddStringToObject(tmp,"receiveAccount",_CellularManagerTemp->sms_recv[i].account);
-                cJSON_AddNumberToObject(tmp,"idx", idx++);
+    int idx = 0;
+    cJSON *array = NULL;
+    for (int i = 0; i < MAIL_RECV_MAX; i++)
+    {
+        if (strlen(_CellularManagerTemp->sms_recv[i].account) > 0)
+        {
+            cJSON *tmp = cJSON_CreateObject();
+            cJSON_AddStringToObject(tmp, "receiveAccount", _CellularManagerTemp->sms_recv[i].account);
+            cJSON_AddNumberToObject(tmp, "idx", idx++);
 
-                if(array==NULL) {
-                    array = cJSON_CreateArray();
-                }
+            if (array == NULL)
+            {
+                array = cJSON_CreateArray();
+            }
 
-                if(array) {
-                    cJSON_AddItemToArray(array, tmp);
-                }
+            if (array)
+            {
+                cJSON_AddItemToArray(array, tmp);
             }
         }
     }
-    if(array) {
+    if (array)
+    {
         cJSON_AddItemToObject(data_root_array, "receiveAccountList", array);
     }
 
-
     if (nWSType)
     {
         // 添加汇总
@@ -4752,11 +4756,12 @@ char* communication_WIFI_ack_to_json(WIFIInfo_t* _WIFIManagertemp,int nWSType)
     //创建数据
     memset(temp, 0, sizeof(temp));
 
-    cJSON *sdata_filed = cJSON_CreateObject();
+    cJSON *sdata_filed = NULL;
     // 创建数据
     cJSON *data_root_array = cJSON_CreateObject();
     if (nWSType)
     {
+        sdata_filed = cJSON_CreateObject();
         cJSON_AddNumberToObject(sdata_filed, "code", 200);
     }
     else