!224 fix 内存泄漏

Merge pull request !224 from 张欣宇/master
This commit is contained in:
openharmony_ci 2024-07-10 03:19:12 +00:00 committed by Gitee
commit 27e60a2729
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 17 additions and 1 deletions

View File

@ -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()) {

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -253,7 +253,7 @@ void from_json(const cJSON* obj, ProvisionInfo& out)
if (dumpString != NULL) {
out.appServiceCapabilities = dumpString;
}
free(dumpString);
cJSON_free(dumpString);
}
}