From 01cfaef1f3e79f1b6176357549e6a3454821b75a Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 27 Oct 2022 15:17:09 +0800 Subject: [PATCH 1/5] =?UTF-8?q?freeWork(work)=E6=8F=90=E5=89=8D=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I523c0543082b6b018506369ac303715391d2f176 --- interfaces/plugin/src/sensor_napi_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/plugin/src/sensor_napi_utils.cpp b/interfaces/plugin/src/sensor_napi_utils.cpp index 4cfecb68..184edfeb 100644 --- a/interfaces/plugin/src/sensor_napi_utils.cpp +++ b/interfaces/plugin/src/sensor_napi_utils.cpp @@ -492,6 +492,7 @@ void EmitUvEventLoop(sptr asyncCallbackInfo) 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)); + freeWork(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 @@ -531,7 +532,6 @@ void EmitUvEventLoop(sptr asyncCallbackInfo) } napi_close_handle_scope(asyncCallbackInfo->env, scope); asyncCallbackInfo->work = nullptr; - freeWork(work); }); if (ret != 0) { SEN_HILOGE("uv_queue_work fail"); -- Gitee From 67cbab9d25b74e4fd6069baf91d5085d6ca10f54 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 27 Oct 2022 15:25:07 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=A2=9E=E5=8A=A0argv[i]=E5=88=A4=E7=A9=BA?= =?UTF-8?q?=EF=BC=8C=E5=8F=AA=E5=9C=A8=E9=9D=9E=E7=A9=BA=E6=97=B6delete[]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I5b8f50b8001b3324d8760dd17331b1beb4dd644e --- services/sensor/src/sensor_dump.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index d1d298b9..5a1c8a0c 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -173,6 +173,9 @@ void SensorDump::ParseCommand(int32_t fd, const std::vector &args, } RELEASE_RES: for (size_t i = 0; i < args.size(); ++i) { + if (argv[i] == nullptr) { + continue; + } delete[] argv[i]; } delete[] argv; -- Gitee From 414fdeac17cc3236663972acf09f81c8fbe8bd16 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 27 Oct 2022 15:43:24 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=99=BA=E8=83=BD=E6=8C=87=E9=92=88?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E4=B8=BAnullptr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I2af2fdbefee7000fffd5eac496c57820ce3bb225 --- services/sensor/include/sensor_service.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 -- Gitee From 89db21e7d477e21e8e9aad52d63c3269967fac46 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 27 Oct 2022 16:25:13 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=B0=86=E7=BB=93=E6=9E=84=E4=BD=93?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=8C=87=E9=92=88=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E4=B8=BAnullptr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I429bb16bd81acf8de557f91175494d2056fa0e93 --- interfaces/native/include/sensor_agent_type.h | 4 ++-- 1 file changed, 2 insertions(+), 2 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; /** -- Gitee From 3e973568f646772ec203a3a5a8755627995a5b1a Mon Sep 17 00:00:00 2001 From: hui1975 Date: Fri, 28 Oct 2022 10:21:30 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=9A=84delete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I62f85dfa4c903ab2da48dfc422b7968429e3fdd1 --- interfaces/plugin/include/async_callback_info.h | 4 ---- interfaces/plugin/src/sensor_napi_utils.cpp | 9 +++------ services/sensor/src/sensor_dump.cpp | 5 ++--- 3 files changed, 5 insertions(+), 13 deletions(-) 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 184edfeb..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,13 +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)); - freeWork(work); + 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 @@ -531,13 +530,11 @@ void EmitUvEventLoop(sptr asyncCallbackInfo) return; } napi_close_handle_scope(asyncCallbackInfo->env, scope); - asyncCallbackInfo->work = nullptr; }); if (ret != 0) { SEN_HILOGE("uv_queue_work fail"); asyncCallbackInfo->DecStrongRef(nullptr); - asyncCallbackInfo->work = nullptr; - freeWork(work); + DeleteWork(work); } } diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index 5a1c8a0c..51553a02 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -173,10 +173,9 @@ void SensorDump::ParseCommand(int32_t fd, const std::vector &args, } RELEASE_RES: for (size_t i = 0; i < args.size(); ++i) { - if (argv[i] == nullptr) { - continue; + if (argv[i] != nullptr) { + delete[] argv[i]; } - delete[] argv[i]; } delete[] argv; } -- Gitee