mirror of
https://gitee.com/openharmony/security_appverify
synced 2024-11-23 14:39:58 +00:00
fix 内存泄漏
Signed-off-by: 张欣宇 <zhangxinyu74@huawei.com> Change-Id: Ic812d554d88f6e5acef8abe8cf17aae1933a9043
This commit is contained in:
parent
1837b2b6cb
commit
c51bc2d574
@ -26,6 +26,10 @@ namespace Verify {
|
||||
bool JsonParserUtils::ReadTrustedRootCAFromJson(cJSON** jsonObj,
|
||||
const std::string& jsonPath, std::string& error)
|
||||
{
|
||||
if (jsonObj == NULL) {
|
||||
error += "jsonObj is NULL";
|
||||
return false;
|
||||
}
|
||||
std::ifstream jsonFileStream;
|
||||
jsonFileStream.open(jsonPath.c_str(), std::ios::in);
|
||||
if (!jsonFileStream.is_open()) {
|
||||
|
@ -112,6 +112,7 @@ bool TrustedRootCa::GetTrustedRootCAFromJson(StringCertMap& rootCertMap, const s
|
||||
if (cert == nullptr) {
|
||||
HAPVERIFY_LOG_ERROR("GetX509CertFromPemString failed, key: %{public}s value: %{public}s",
|
||||
jsonPair.first.c_str(), jsonPair.second.c_str());
|
||||
cJSON_Delete(trustedRootCAJson);
|
||||
return false;
|
||||
}
|
||||
rootCertMap[jsonPair.first] = cert;
|
||||
@ -119,6 +120,7 @@ bool TrustedRootCa::GetTrustedRootCAFromJson(StringCertMap& rootCertMap, const s
|
||||
|
||||
if (rootCertMap.empty()) {
|
||||
HAPVERIFY_LOG_ERROR("no root cert");
|
||||
cJSON_Delete(trustedRootCAJson);
|
||||
return false;
|
||||
}
|
||||
cJSON_Delete(trustedRootCAJson);
|
||||
|
@ -107,24 +107,29 @@ bool TrustedSourceManager::GetAppTrustedSources(SourceInfoVec& trustedAppSources
|
||||
}
|
||||
if (!JsonParserUtils::GetJsonString(trustedSourceJson, KEY_OF_APP_TRUSTED_SOURCE_VERSION, souucesVersion)) {
|
||||
HAPVERIFY_LOG_ERROR("get version failed");
|
||||
cJSON_Delete(trustedSourceJson);
|
||||
return false;
|
||||
}
|
||||
if (!JsonParserUtils::GetJsonString(trustedSourceJson,
|
||||
KEY_OF_APP_TRUSTED_SOURCE_RELEASETIME, souucesReleaseTime)) {
|
||||
HAPVERIFY_LOG_ERROR("get releaseTime failed");
|
||||
cJSON_Delete(trustedSourceJson);
|
||||
return false;
|
||||
}
|
||||
JsonObjVec trustedAppSourceJson;
|
||||
if (!JsonParserUtils::ParseJsonToObjVec(trustedSourceJson, KEY_OF_APP_TRUSTED_SOURCE, trustedAppSourceJson)) {
|
||||
HAPVERIFY_LOG_ERROR("get JsonObjVec failed");
|
||||
cJSON_Delete(trustedSourceJson);
|
||||
return false;
|
||||
}
|
||||
if (!ParseTrustedAppSourceJson(trustedAppSources, trustedAppSourceJson)) {
|
||||
HAPVERIFY_LOG_ERROR("parse JsonObjVec failed");
|
||||
cJSON_Delete(trustedSourceJson);
|
||||
return false;
|
||||
}
|
||||
if (trustedAppSources.empty()) {
|
||||
HAPVERIFY_LOG_ERROR("no app trusted source");
|
||||
cJSON_Delete(trustedSourceJson);
|
||||
return false;
|
||||
}
|
||||
cJSON_Delete(trustedSourceJson);
|
||||
|
@ -80,24 +80,29 @@ bool TrustedTicketManager::GetTicketTrustedSources(TicketSourceInfoVec& trustedT
|
||||
}
|
||||
if (!JsonParserUtils::GetJsonString(trustedSourceJson, KEY_OF_TICKET_TRUSTED_SOURCE_VERSION, sourcesVersion)) {
|
||||
HAPVERIFY_LOG_ERROR("get version failed");
|
||||
cJSON_Delete(trustedSourceJson);
|
||||
return false;
|
||||
}
|
||||
if (!JsonParserUtils::GetJsonString(trustedSourceJson,
|
||||
KEY_OF_TICKET_TRUSTED_SOURCE_RELEASETIME, sourcesReleaseTime)) {
|
||||
HAPVERIFY_LOG_ERROR("get releaseTime failed");
|
||||
cJSON_Delete(trustedSourceJson);
|
||||
return false;
|
||||
}
|
||||
JsonObjVec trustedTicketJson;
|
||||
if (!JsonParserUtils::ParseJsonToObjVec(trustedSourceJson, KEY_OF_TICKET_TRUSTED_SOURCE, trustedTicketJson)) {
|
||||
HAPVERIFY_LOG_ERROR("get JsonObjVec failed");
|
||||
cJSON_Delete(trustedSourceJson);
|
||||
return false;
|
||||
}
|
||||
if (!ParseTrustedTicketSourceJson(trustedTicketSources, trustedTicketJson)) {
|
||||
HAPVERIFY_LOG_ERROR("parse JsonObjVec failed");
|
||||
cJSON_Delete(trustedSourceJson);
|
||||
return false;
|
||||
}
|
||||
if (trustedTicketSources.empty()) {
|
||||
HAPVERIFY_LOG_ERROR("no ticket trusted source");
|
||||
cJSON_Delete(trustedSourceJson);
|
||||
return false;
|
||||
}
|
||||
cJSON_Delete(trustedSourceJson);
|
||||
|
@ -253,7 +253,7 @@ void from_json(const cJSON* obj, ProvisionInfo& out)
|
||||
if (dumpString != NULL) {
|
||||
out.appServiceCapabilities = dumpString;
|
||||
}
|
||||
free(dumpString);
|
||||
cJSON_free(dumpString);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user