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