diff --git a/frameworks/extension/src/work_scheduler_extension.cpp b/frameworks/extension/src/work_scheduler_extension.cpp index ec356023f2566751c9b34788c875368348023303..eedf8eaf1a48354673f6ec79ca8b354c7b4375b6 100644 --- a/frameworks/extension/src/work_scheduler_extension.cpp +++ b/frameworks/extension/src/work_scheduler_extension.cpp @@ -23,13 +23,13 @@ namespace WorkScheduler { WorkSchedulerExtension* WorkSchedulerExtension::Create(const std::unique_ptr& runtime) { if (!runtime) { - return new WorkSchedulerExtension(); + return (new (std::nothrow) WorkSchedulerExtension()); } switch (runtime->GetLanguage()) { case AbilityRuntime::Runtime::Language::JS: return JsWorkSchedulerExtension::Create(runtime); default: - return new WorkSchedulerExtension(); + return (new (std::nothrow) WorkSchedulerExtension()); } } diff --git a/services/native/src/conditions/battery_level_listener.cpp b/services/native/src/conditions/battery_level_listener.cpp index b55313610a2fd76bd793dfa6aa9e337d21657ea6..177f187815b338ca09b35f7683604f0914097762 100644 --- a/services/native/src/conditions/battery_level_listener.cpp +++ b/services/native/src/conditions/battery_level_listener.cpp @@ -32,7 +32,7 @@ void BatteryLevelEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData WS_HILOGI("OnReceiveEvent get action: %{public}s", action.c_str()); if (action == EventFwk::CommonEventSupport::COMMON_EVENT_BATTERY_CHANGED) { if (data.GetCode() == PowerMgr::BatteryInfo::COMMON_EVENT_CODE_CAPACITY) { - int battCap = atoi(data.GetData().c_str()); + int battCap = stoi(data.GetData()); listener_.OnConditionChanged(WorkCondition::Type::BATTERY_LEVEL, std::make_shared(battCap, 0, 0, std::string())); } diff --git a/services/native/src/conditions/charger_listener.cpp b/services/native/src/conditions/charger_listener.cpp index 52cbdc4b7dca782713f3fcf801c827160931ad8f..6883ff0d42efda3823afef39cdacd043f0f454f5 100644 --- a/services/native/src/conditions/charger_listener.cpp +++ b/services/native/src/conditions/charger_listener.cpp @@ -33,7 +33,7 @@ void ChargerEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &dat if (action == EventFwk::CommonEventSupport::COMMON_EVENT_POWER_CONNECTED) { int code = data.GetCode(); if (code == PowerMgr::BatteryInfo::COMMON_EVENT_CODE_PLUGGED_TYPE) { - int type = atoi(data.GetData().c_str()); + int type = stoi(data.GetData()); switch (type) { case static_cast(PowerMgr::BatteryPluggedType::PLUGGED_TYPE_AC): WS_HILOGI("Condition changed: CHARGER_PLUGGED_AC"); @@ -60,7 +60,7 @@ void ChargerEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &dat } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_POWER_DISCONNECTED) { int code = data.GetCode(); if (code == PowerMgr::BatteryInfo::COMMON_EVENT_CODE_PLUGGED_TYPE) { - int type = atoi(data.GetData().c_str()); + int type = stoi(data.GetData()); switch (type) { case static_cast(PowerMgr::BatteryPluggedType::PLUGGED_TYPE_NONE): case static_cast(PowerMgr::BatteryPluggedType::PLUGGED_TYPE_BUTT): diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index ae9d04418f8ee62b8843ef3550873db91aa030bb..9526db82689fcaf8aec98ac0dce9fad8e7eb455d 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -144,6 +144,7 @@ list> WorkSchedulerService::ReadPersistedWorks() Json::CharReaderBuilder readerBuilder; const unique_ptr jsonReader(readerBuilder.newCharReader()); bool res = jsonReader->parse(data.c_str(), data.c_str() + data.length(), &root, &errs); + fin.close(); if (!res || !errs.empty()) { return workInfos; }