From 406633937c8559bb64bbd6e4f7b2a771ad58445c Mon Sep 17 00:00:00 2001 From: lvcong_oh Date: Mon, 7 Apr 2025 15:31:52 +0800 Subject: [PATCH] fix memory leak bug Signed-off-by: lvcong_oh --- .../framework/cloud/cloud_server.cpp | 10 ++++++++++ .../framework/include/cloud/cloud_server.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/services/distributeddataservice/framework/cloud/cloud_server.cpp b/services/distributeddataservice/framework/cloud/cloud_server.cpp index 2841cf0b2..f547b7ef3 100644 --- a/services/distributeddataservice/framework/cloud/cloud_server.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_server.cpp @@ -21,9 +21,19 @@ CloudServer *CloudServer::GetInstance() return instance_; } +CloudServer::~CloudServer() +{ + if (instance_ != nullptr) { + delete instance_; + instance_ = nullptr; + } +} bool CloudServer::RegisterCloudInstance(CloudServer *instance) { if (instance_ != nullptr) { + if (instance != nullptr) { + delete instance; + } return false; } instance_ = instance; diff --git a/services/distributeddataservice/framework/include/cloud/cloud_server.h b/services/distributeddataservice/framework/include/cloud/cloud_server.h index 9cb060c81..ac82de30b 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_server.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_server.h @@ -45,6 +45,8 @@ public: virtual bool IsSupportCloud(int32_t userId); private: + virtual ~CloudServer(); + static CloudServer *instance_; }; } // namespace OHOS::DistributedData -- Gitee