diff --git a/services/distributeddataservice/framework/cloud/cloud_server.cpp b/services/distributeddataservice/framework/cloud/cloud_server.cpp index 2841cf0b29aabee3ecd2b7e37b86428217946d42..f547b7ef3d32a0410da135a9a8db1a44bfe702c5 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 9cb060c81f0b941b0356242c364dcf0d477df30a..ac82de30b33bb806d667aeac4897d2041a409cf3 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