diff --git a/interfaces/native/include/sensor_agent_type.h b/interfaces/native/include/sensor_agent_type.h index 85531a585d586719192e43621f5fc0bf4775ef02..78479e4ed9b30879d7be9ad09b16d55c54f5c61d 100644 --- a/interfaces/native/include/sensor_agent_type.h +++ b/interfaces/native/include/sensor_agent_type.h @@ -126,7 +126,7 @@ typedef struct SensorEvent { int64_t timestamp; /**< Time when sensor data was reported */ uint32_t option; /**< Sensor data options, including the measurement range and accuracy */ int32_t mode; /**< Sensor data reporting mode (described in {@link SensorMode}) */ - uint8_t *data; /**< Sensor data */ + uint8_t *data = nullptr; /**< Sensor data */ uint32_t dataLen; /**< Sensor data length */ } SensorEvent; @@ -154,7 +154,7 @@ typedef struct UserData { typedef struct SensorUser { char name[NAME_MAX_LEN]; /**< Name of the sensor data subscriber */ RecordSensorCallback callback; /**< Callback for reporting sensor data */ - UserData *userData; /**< Reserved field for the sensor data subscriber */ + UserData *userData = nullptr; /**< Reserved field for the sensor data subscriber */ } SensorUser; /** diff --git a/interfaces/plugin/include/async_callback_info.h b/interfaces/plugin/include/async_callback_info.h index 2d515f213513d9b470ce0ae31ae4a4c4ab3d56db..94b3512b98c28057bd03ecfb6ac32c717d5c5430 100644 --- a/interfaces/plugin/include/async_callback_info.h +++ b/interfaces/plugin/include/async_callback_info.h @@ -121,10 +121,6 @@ public: napi_delete_reference(env, callback[i]); } } - if (work != nullptr) { - delete work; - work = nullptr; - } } private: diff --git a/interfaces/plugin/src/sensor_napi_utils.cpp b/interfaces/plugin/src/sensor_napi_utils.cpp index 4cfecb6827b2522fc6282b6e9610e95323881325..4ee5a4b4ff068f6ba302e37211268e213201df33 100644 --- a/interfaces/plugin/src/sensor_napi_utils.cpp +++ b/interfaces/plugin/src/sensor_napi_utils.cpp @@ -471,7 +471,7 @@ void EmitAsyncCallbackWork(sptr asyncCallbackInfo) } } -void freeWork(uv_work_t *work) +void DeleteWork(uv_work_t *work) { CHKPV(work); delete work; @@ -486,12 +486,12 @@ void EmitUvEventLoop(sptr asyncCallbackInfo) CHKPV(loop); uv_work_t *work = new(std::nothrow) uv_work_t; CHKPV(work); - asyncCallbackInfo->work = work; asyncCallbackInfo->IncStrongRef(nullptr); work->data = asyncCallbackInfo.GetRefPtr(); int32_t ret = uv_queue_work(loop, work, [] (uv_work_t *work) { }, [] (uv_work_t *work, int status) { CHKPV(work); sptr asyncCallbackInfo(static_cast(work->data)); + DeleteWork(work); /** * After the asynchronous task is created, the asyncCallbackInfo reference count is reduced * to 0 destructions, so you need to add 1 to the asyncCallbackInfo reference count when the @@ -530,14 +530,11 @@ void EmitUvEventLoop(sptr asyncCallbackInfo) return; } napi_close_handle_scope(asyncCallbackInfo->env, scope); - asyncCallbackInfo->work = nullptr; - freeWork(work); }); if (ret != 0) { SEN_HILOGE("uv_queue_work fail"); asyncCallbackInfo->DecStrongRef(nullptr); - asyncCallbackInfo->work = nullptr; - freeWork(work); + DeleteWork(work); } } diff --git a/services/sensor/include/sensor_service.h b/services/sensor/include/sensor_service.h index a436cf89adc7c5377f994b9f4f67c6af91248997..62137d5bd8fc4c2314852c2fc6e6151d418c160c 100644 --- a/services/sensor/include/sensor_service.h +++ b/services/sensor/include/sensor_service.h @@ -78,11 +78,11 @@ private: ClientInfo &clientInfo_ = ClientInfo::GetInstance(); SensorManager &sensorManager_ = SensorManager::GetInstance(); FlushInfoRecord &flushInfo_ = FlushInfoRecord::GetInstance(); - sptr sensorDataProcesser_; - sptr reportDataCallback_; + sptr sensorDataProcesser_ = nullptr; + sptr reportDataCallback_ = nullptr; std::mutex uidLock_; // death recipient of sensor client - sptr clientDeathObserver_; + sptr clientDeathObserver_ = nullptr; ErrCode SaveSubscriber(uint32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs); }; } // namespace Sensors diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index d1d298b904f82bf1703aa9447056f37af4612768..51553a02e57479bf76fb0e8b53c55c954f587170 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -173,7 +173,9 @@ void SensorDump::ParseCommand(int32_t fd, const std::vector &args, } RELEASE_RES: for (size_t i = 0; i < args.size(); ++i) { - delete[] argv[i]; + if (argv[i] != nullptr) { + delete[] argv[i]; + } } delete[] argv; }