Skip to content

Commit 79a95e2

Browse files
author
Spike Lin
committed
1. 修复OTA内存泄漏
2. 修复设备信息json文件不完整导致的段错误
1 parent d62a536 commit 79a95e2

File tree

4 files changed

+71
-6
lines changed

4 files changed

+71
-6
lines changed

platform/os/linux/HAL_Device_linux.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,52 @@ static int iot_parse_devinfo_from_json_file(DeviceInfo *pDevInfo)
154154

155155
if(len != rlen){
156156
Log_e("read data len (%d) less than needed (%d), %s", rlen, len, JsonDoc);
157+
ret = QCLOUD_ERR_FAILURE;
158+
goto exit;
157159
}
158160

159161
/*Get device info*/
160162
char* authMode = LITE_json_value_of(KEY_AUTH_MODE, JsonDoc);
161163
char* productId = LITE_json_value_of(KEY_PRODUCT_ID, JsonDoc);
162164
char* devName = LITE_json_value_of(KEY_DEV_NAME, JsonDoc);
163-
165+
166+
if(NULL == authMode || NULL == productId || NULL == devName) {
167+
Log_e("read device data from json file failed!");
168+
ret = QCLOUD_ERR_FAILURE;
169+
goto exit;
170+
}
171+
164172
strncpy(pDevInfo->product_id, productId, MAX_SIZE_OF_PRODUCT_ID);
165173
strncpy(pDevInfo->device_name, devName, MAX_SIZE_OF_DEVICE_NAME);
166174

167175
#ifdef DEV_DYN_REG_ENABLED
168176
char* productSecret = LITE_json_value_of(KEY_PRODUCT_SECRET, JsonDoc);
177+
if(NULL == productSecret) {
178+
Log_e("read product secret from json file failed!");
179+
ret = QCLOUD_ERR_FAILURE;
180+
goto exit;
181+
}
169182
strncpy(pDevInfo->product_secret, productSecret, MAX_SIZE_OF_PRODUCT_SECRET);
170183
#endif
171184

172185
#ifdef AUTH_MODE_CERT
173186
char* devCrtFileName = LITE_json_value_of(KEY_DEV_CERT, JsonDoc);
174187
char* devKeyFileName = LITE_json_value_of(KEY_DEV_PRIVATE_KEY, JsonDoc);
188+
if(NULL == devCrtFileName || NULL == devKeyFileName) {
189+
Log_e("read cert file name from json file failed!");
190+
ret = QCLOUD_ERR_FAILURE;
191+
goto exit;
192+
}
175193
strncpy(pDevInfo->dev_cert_file_name, devCrtFileName, MAX_SIZE_OF_DEVICE_CERT_FILE_NAME);
176194
strncpy(pDevInfo->dev_key_file_name, devKeyFileName, MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME);
177195
//Log_d("mode:%s, pid:%s, devName:%s, devCrtFileName:%s, devKeyFileName:%s", authMode, productId, devName, devCrtFileName, devKeyFileName);
178196
#else
179197
char* devSecret = LITE_json_value_of(KEY_DEV_SECRET, JsonDoc);
198+
if(NULL == devSecret) {
199+
Log_e("read device secret from json file failed!");
200+
ret = QCLOUD_ERR_FAILURE;
201+
goto exit;
202+
}
180203
strncpy(pDevInfo->device_secret, devSecret, MAX_SIZE_OF_DEVICE_SECRET);
181204
//Log_d("mode:%s, pid:%s, devName:%s, devSerect:%s", authMode, productId, devName, devSecret);
182205
#endif
@@ -258,7 +281,13 @@ static int iot_parse_subdevinfo_from_json_file(DeviceInfo *pDevInfo)
258281
/*Get sub device info*/
259282
char* productId = LITE_json_value_of(KEY_SUBDEV_PRODUCT_ID, JsonDoc);
260283
char* devName = LITE_json_value_of(KEY_SUBDEV_NAME, JsonDoc);
261-
284+
285+
if(NULL == productId || NULL == devName) {
286+
Log_e("read sub device data from json file failed!");
287+
ret = QCLOUD_ERR_FAILURE;
288+
goto exit;
289+
}
290+
262291
strncpy(pDevInfo->product_id, productId, MAX_SIZE_OF_PRODUCT_ID);
263292
strncpy(pDevInfo->device_name, devName, MAX_SIZE_OF_DEVICE_NAME);
264293
//Log_d("pid:%s, devName:%s", productId, devName);

platform/os/windows/HAL_Device_win.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,52 @@ static int iot_parse_devinfo_from_json_file(DeviceInfo *pDevInfo)
154154

155155
if(len != rlen){
156156
Log_e("read data len (%d) less than needed (%d), %s", rlen, len, JsonDoc);
157+
ret = QCLOUD_ERR_FAILURE;
158+
goto exit;
157159
}
158160

159161
/*Get device info*/
160162
char* authMode = LITE_json_value_of(KEY_AUTH_MODE, JsonDoc);
161163
char* productId = LITE_json_value_of(KEY_PRODUCT_ID, JsonDoc);
162164
char* devName = LITE_json_value_of(KEY_DEV_NAME, JsonDoc);
163-
165+
166+
if(NULL == authMode || NULL == productId || NULL == devName) {
167+
Log_e("read device data from json file failed!");
168+
ret = QCLOUD_ERR_FAILURE;
169+
goto exit;
170+
}
171+
164172
strncpy(pDevInfo->product_id, productId, MAX_SIZE_OF_PRODUCT_ID);
165173
strncpy(pDevInfo->device_name, devName, MAX_SIZE_OF_DEVICE_NAME);
166174

167175
#ifdef DEV_DYN_REG_ENABLED
168176
char* productSecret = LITE_json_value_of(KEY_PRODUCT_SECRET, JsonDoc);
177+
if(NULL == productSecret) {
178+
Log_e("read product secret from json file failed!");
179+
ret = QCLOUD_ERR_FAILURE;
180+
goto exit;
181+
}
169182
strncpy(pDevInfo->product_secret, productSecret, MAX_SIZE_OF_PRODUCT_SECRET);
170183
#endif
171184

172185
#ifdef AUTH_MODE_CERT
173186
char* devCrtFileName = LITE_json_value_of(KEY_DEV_CERT, JsonDoc);
174187
char* devKeyFileName = LITE_json_value_of(KEY_DEV_PRIVATE_KEY, JsonDoc);
188+
if(NULL == devCrtFileName || NULL == devKeyFileName) {
189+
Log_e("read cert file name from json file failed!");
190+
ret = QCLOUD_ERR_FAILURE;
191+
goto exit;
192+
}
175193
strncpy(pDevInfo->dev_cert_file_name, devCrtFileName, MAX_SIZE_OF_DEVICE_CERT_FILE_NAME);
176194
strncpy(pDevInfo->dev_key_file_name, devKeyFileName, MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME);
177-
//Log_d("mode:%s, pid:%s, devName:%s, devCrtFileName:%s, devKeyFileName:%s", authMode, productId, devName, devCrtFileName, devKeyFileName);
195+
//Log_d("mode:%s, pid:%s, devName:%s, devCrtFileName:%s, devKeyFileName:%s", authMode, productId, devName, devCrtFileName, devKeyFileName);
178196
#else
179197
char* devSecret = LITE_json_value_of(KEY_DEV_SECRET, JsonDoc);
198+
if(NULL == devSecret) {
199+
Log_e("read device secret from json file failed!");
200+
ret = QCLOUD_ERR_FAILURE;
201+
goto exit;
202+
}
180203
strncpy(pDevInfo->device_secret, devSecret, MAX_SIZE_OF_DEVICE_SECRET);
181204
//Log_d("mode:%s, pid:%s, devName:%s, devSerect:%s", authMode, productId, devName, devSecret);
182205
#endif
@@ -258,10 +281,16 @@ static int iot_parse_subdevinfo_from_json_file(DeviceInfo *pDevInfo)
258281
/*Get sub device info*/
259282
char* productId = LITE_json_value_of(KEY_SUBDEV_PRODUCT_ID, JsonDoc);
260283
char* devName = LITE_json_value_of(KEY_SUBDEV_NAME, JsonDoc);
261-
284+
285+
if(NULL == productId || NULL == devName) {
286+
Log_e("read sub device data from json file failed!");
287+
ret = QCLOUD_ERR_FAILURE;
288+
goto exit;
289+
}
290+
262291
strncpy(pDevInfo->product_id, productId, MAX_SIZE_OF_PRODUCT_ID);
263292
strncpy(pDevInfo->device_name, devName, MAX_SIZE_OF_DEVICE_NAME);
264-
Log_d("pid:%s, devName:%s", productId, devName);
293+
//Log_d("pid:%s, devName:%s", productId, devName);
265294

266295
if(productId){
267296
HAL_Free(productId);

sdk_src/services/ota/ota_client.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ static void _ota_callback(void *pcontext, const char *msg, uint32_t msg_len) {
109109
goto End;
110110
}
111111

112+
if(NULL != json_type) {
113+
HAL_Free(json_type);
114+
json_type = NULL;
115+
}
116+
112117
if (0 != qcloud_otalib_get_params(msg, &json_type, &h_ota->purl, &h_ota->version,
113118
h_ota->md5sum, &h_ota->size_file)) {
114119
Log_e("Get firmware parameter failed");

sdk_src/services/ota/ota_lib.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,11 @@ int qcloud_otalib_get_report_version_result(const char *json)
184184

185185
int rc = _qcloud_otalib_get_firmware_varlen_para(json, RESULT_FIELD, &result_code);
186186
if ( rc != QCLOUD_RET_SUCCESS || strcmp(result_code, "0") != 0) {
187+
if(NULL != result_code) HAL_Free(result_code);
187188
IOT_FUNC_EXIT_RC(IOT_OTA_ERR_FAIL);
188189
}
189190

191+
if(NULL != result_code) HAL_Free(result_code);
190192
IOT_FUNC_EXIT_RC(QCLOUD_RET_SUCCESS);
191193
}
192194

0 commit comments

Comments
 (0)