OCT 1. 修正一处cJSON解析内存泄漏问题

This commit is contained in:
huangxin 2023-02-20 17:23:21 +08:00
parent 7ee3cd9041
commit 782847018f
1 changed files with 7 additions and 7 deletions

View File

@ -36,7 +36,7 @@ const char *proto_decode_context(const char *pString, unsigned int *pVer, unsign
cJSON *pCrypto = cJSON_GetObjectItem(pRoot, "cryptoType");
if (!pCrypto) {
cJSON_free(pRoot);
cJSON_Delete(pRoot);
return NULL;
}
@ -59,13 +59,13 @@ const char *proto_decode_context(const char *pString, unsigned int *pVer, unsign
pMsgCtx = cJSON_GetObjectItem(pRoot, "msgContent");
if (!pMsgCtx) {
cJSON_free(pRoot);
cJSON_Delete(pRoot);
return NULL;
}
switch (pCrypto->valueint) {
case CRYPTO_NONE:
pMsgContent = strdup(cJSON_Print(pMsgCtx));
pMsgContent = cJSON_Print(pMsgCtx);
break;
case CRYPTO_BASE64:
pMsgContent = (char *)base64_decode(pMsgCtx->valuestring, (unsigned int *)&outSize);
@ -83,7 +83,7 @@ const char *proto_decode_context(const char *pString, unsigned int *pVer, unsign
} else if (pCrypto->valueint == CRYPTO_3DES) {
cryptoType = DES3_ECB_PKCS7PADDING;
} else {
cJSON_free(pRoot);
cJSON_Delete(pRoot);
return NULL;
}
@ -95,7 +95,7 @@ const char *proto_decode_context(const char *pString, unsigned int *pVer, unsign
if (pMsgContent) {
free(pMsgContent);
}
cJSON_free(pRoot);
cJSON_Delete(pRoot);
return NULL;
} else {
pMsgContent[decodeSize] = 0;
@ -104,7 +104,7 @@ const char *proto_decode_context(const char *pString, unsigned int *pVer, unsign
} break;
}
cJSON_free(pRoot);
cJSON_Delete(pRoot);
return pMsgContent;
}
@ -200,7 +200,7 @@ const char *proto_create_new(cJSON *pMsgCtx, int httpCode) {
return NULL;
}
pStrProto = cJSON_Print(pRoot);
pStrProto = cJSON_PrintUnformatted(pRoot);
LOG_MOD(debug, ZLOG_MOD_PROTO, "Create: \n%s\n", pStrProto);
cJSON_Delete(pRoot);