diff --git a/frameworks/bundle_lite/src/ability_info_utils.cpp b/frameworks/bundle_lite/src/ability_info_utils.cpp index 1954af6..1edb109 100644 --- a/frameworks/bundle_lite/src/ability_info_utils.cpp +++ b/frameworks/bundle_lite/src/ability_info_utils.cpp @@ -207,7 +207,7 @@ bool AbilityInfoUtils::SetAbilityInfoSkill(AbilityInfo *abilityInfo, Skill * con if (skills[i] == nullptr) { return false; } - abilityInfo->skills[i] = (Skill *)AdapterMalloc(sizeof(Skill)); + abilityInfo->skills[i] = static_cast(AdapterMalloc(sizeof(Skill))); CopyStringArray(abilityInfo->skills[i]->entities, skills[i]->entities, MAX_SKILL_ITEM); CopyStringArray(abilityInfo->skills[i]->actions, skills[i]->actions, MAX_SKILL_ITEM); } diff --git a/frameworks/bundle_lite/src/bundle_manager.cpp b/frameworks/bundle_lite/src/bundle_manager.cpp index 44d1c4a..b3678b8 100644 --- a/frameworks/bundle_lite/src/bundle_manager.cpp +++ b/frameworks/bundle_lite/src/bundle_manager.cpp @@ -793,6 +793,7 @@ uint8_t GetBundleNameForUid(int32_t uid, char **bundleName) resultOfGetBundleNameForUid.bundleName, resultOfGetBundleNameForUid.length); AdapterFree(resultOfGetBundleNameForUid.bundleName); if (err != EOK) { + AdapterFree(*bundleName); return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR; } return resultOfGetBundleNameForUid.resultCode; diff --git a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp index 11a0495..4350337 100644 --- a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp +++ b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp @@ -60,9 +60,6 @@ bool BundleMsClient::Initialize() const bool BundleMsClient::Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback) const { - if (g_bmsbuff == nullptr) { - g_bmsbuff = reinterpret_cast(OhosMalloc(MEM_TYPE_APPFMK_LSRAM, sizeof(Bmsbuff))); - } BundleMgrService *service = BundleMgrService::GetInstance(); if (service == nullptr) { return false; @@ -70,22 +67,23 @@ bool BundleMsClient::Install(const char *hapPath, const InstallParam *installPar if (hapPath == nullptr) { return false; } - - if (memset_s(g_bmsbuff->bundleParameter, MAX_PATH_LEN, 0, MAX_PATH_LEN) != 0) { - return false; - } int len = strlen(hapPath); if (len >= MAX_PATH_LEN) { return false; } - if (memcpy_s(g_bmsbuff->bundleParameter, MAX_PATH_LEN, hapPath, len + 1) != 0) { + Bmsbuff *data = static_cast(AdapterMalloc(sizeof(Bmsbuff))); + if (data == nullptr) { return false; } - g_bmsbuff->bundleInstallerCallback = installerCallback; + if (memcpy_s(data->bundleParameter, MAX_PATH_LEN, hapPath, len + 1) != 0) { + AdapterFree(data); + return false; + } + data->bundleInstallerCallback = installerCallback; Request request = { .msgId = BMS_INSTALL_MSG, - .len = 0, - .data = nullptr, + .len = sizeof(Bmsbuff), + .data = data, .msgValue = 0, }; @@ -103,24 +101,23 @@ bool BundleMsClient::Uninstall (const char *bundleName, const InstallParam *inst if (bundleName == nullptr) { return false; } - if (g_bmsbuff == nullptr) { - g_bmsbuff = reinterpret_cast(OhosMalloc(MEM_TYPE_APPFMK_LSRAM, sizeof(Bmsbuff))); - } - if (memset_s(g_bmsbuff->bundleParameter, MAX_PATH_LEN, 0, MAX_PATH_LEN) != 0) { - return false; - } int len = strlen(bundleName); if (len >= MAX_PATH_LEN) { return false; } - if (memcpy_s(g_bmsbuff->bundleParameter, MAX_PATH_LEN, bundleName, len + 1) != 0) { + Bmsbuff *data = static_cast(AdapterMalloc(sizeof(Bmsbuff))); + if (data == nullptr) { return false; } - g_bmsbuff->bundleInstallerCallback = installerCallback; + if (memcpy_s(data->bundleParameter, MAX_PATH_LEN, bundleName, len + 1) != 0) { + AdapterFree(data); + return false; + } + data->bundleInstallerCallback = installerCallback; Request request = { .msgId = BMS_UNINSTALL_MSG, - .len = 0, - .data = nullptr, + .len = sizeof(Bmsbuff), + .data = data, .msgValue = 0, }; int32_t ret = SAMGR_SendRequest(service->GetIdentity(), &request, nullptr); diff --git a/services/bundlemgr_lite/src/bundle_info_creator.cpp b/services/bundlemgr_lite/src/bundle_info_creator.cpp index a95a631..065f32e 100755 --- a/services/bundlemgr_lite/src/bundle_info_creator.cpp +++ b/services/bundlemgr_lite/src/bundle_info_creator.cpp @@ -48,12 +48,16 @@ uint8_t BundleInfoCreator::SaveBundleInfo(const BundleProfile &bundleProfile, Bu size_t index = std::string(info->codePath).find_last_of(PATH_SEPARATOR); if (index == std::string::npos) { HILOG_ERROR(HILOG_MODULE_APP, "codePath is invalid!"); + BundleInfoUtils::FreeBundleInfo(*bundleInfo); + *bundleInfo = nullptr; return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; } installDirPath = std::string(info->codePath).substr(0, index); index = std::string(info->dataPath).find_last_of(PATH_SEPARATOR); if (index == std::string::npos) { HILOG_ERROR(HILOG_MODULE_APP, "dataPath is invalid!"); + BundleInfoUtils::FreeBundleInfo(*bundleInfo); + *bundleInfo = nullptr; return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; } dataDirPath = std::string(info->dataPath).substr(0, index); diff --git a/services/bundlemgr_lite/src/bundle_mgr_service.cpp b/services/bundlemgr_lite/src/bundle_mgr_service.cpp index c953e23..51e096d 100644 --- a/services/bundlemgr_lite/src/bundle_mgr_service.cpp +++ b/services/bundlemgr_lite/src/bundle_mgr_service.cpp @@ -86,12 +86,20 @@ BOOL BundleMgrService::ServiceMessageHandle(Service *service, Request *request) if (request == nullptr) { return FALSE; } - if (request->msgId == BMS_INSTALL_MSG && g_bmsbuff != nullptr) { - OHOS::GtManagerService::GetInstance().Install(g_bmsbuff->bundleParameter, nullptr, - g_bmsbuff->bundleInstallerCallback); - } else if (request->msgId == BMS_UNINSTALL_MSG && g_bmsbuff != nullptr) { - OHOS::GtManagerService::GetInstance().Uninstall(g_bmsbuff->bundleParameter, nullptr, - g_bmsbuff->bundleInstallerCallback); + if (request->msgId == BMS_INSTALL_MSG) { + Bmsbuff *data = static_cast(request->data); + OHOS::GtManagerService::GetInstance().Install(data->bundleParameter, nullptr, + data->bundleInstallerCallback); + AdapterFree(request->data); + request->data = nullptr; + request->len = 0; + } else if (request->msgId == BMS_UNINSTALL_MSG) { + Bmsbuff *data = static_cast(request->data); + OHOS::GtManagerService::GetInstance().Uninstall(data->bundleParameter, nullptr, + data->bundleInstallerCallback); + AdapterFree(request->data); + request->data = nullptr; + request->len = 0; } else if (request->msgId == BMS_SCAN_PACKAGE_MSG) { OHOS::GtManagerService::GetInstance().ScanPackages(); } else if (request->msgId == BMS_REGISTER_CALLBACK_MSG && g_bmsbuff != nullptr) { diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index 2caaa76..5b8d15f 100644 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -350,8 +350,8 @@ bool GtManagerService::MatchSkills(const Want *want, Skill *const skills[]) } bool GtManagerService::isMatchActions(const char *actions, char *const skillActions[]) { - if (actions == nullptr && skillActions == nullptr) { - return true; + if (actions == nullptr || skillActions == nullptr) { + return false; } for (int32_t i = 0; i < MAX_SKILL_ITEM; i++) { if (skillActions[i] == nullptr) { @@ -953,6 +953,9 @@ void GtManagerService::TransformJsToBcWhenRestart(const char *codePath, const ch } cJSON *oldJsEngineVerObj = cJSON_GetObjectItem(installRecordJson, JSON_SUB_KEY_JSENGINE_VERSION); + if (oldJsEngineVerObj == nullptr) { + return; + } if (cJSON_IsString(oldJsEngineVerObj) && strcmp(oldJsEngineVerObj->valuestring, jsEngineVer_) == 0) { cJSON_Delete(jsEngineVerObj); cJSON *transformResultObj = cJSON_GetObjectItem(installRecordJson, JSON_SUB_KEY_TRANSFORM_RESULT); diff --git a/services/bundlemgr_lite/src/gt_bundle_parser.cpp b/services/bundlemgr_lite/src/gt_bundle_parser.cpp index 44134fb..ed2fe3d 100644 --- a/services/bundlemgr_lite/src/gt_bundle_parser.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_parser.cpp @@ -15,8 +15,8 @@ #include "gt_bundle_parser.h" -#include -#include +#include +#include #include "ability_info_utils.h" #include "adapter.h"