From d73d4e1b58879fb08b31825bd98583da469b6117 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Fri, 18 Nov 2022 16:35:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=9BSensor&=E5=A4=9A=E6=A8=A1=E8=B4=A8?= =?UTF-8?q?=E9=87=8F=E5=8A=A0=E5=9B=BA=E4=BB=A3=E7=A0=81=E6=A3=80=E8=A7=86?= =?UTF-8?q?--=E6=B3=9Bsensor=E5=91=8A=E8=AD=A6=E5=8F=8A=E4=B8=93=E9=A1=B9?= =?UTF-8?q?=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I0053446f972c5084f37b374a1554b222e44d8480 --- interfaces/native/include/sensor_agent_type.h | 4 ++-- interfaces/plugin/include/async_callback_info.h | 4 ---- interfaces/plugin/src/sensor_napi_utils.cpp | 9 +++------ services/sensor/include/sensor_service.h | 6 +++--- services/sensor/src/sensor_dump.cpp | 4 +++- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/interfaces/native/include/sensor_agent_type.h b/interfaces/native/include/sensor_agent_type.h index 85531a58..78479e4e 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 2d515f21..94b3512b 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 4cfecb68..4ee5a4b4 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 a436cf89..62137d5b 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 d1d298b9..51553a02 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; } -- Gitee