Fix memory leak 20/251120/3
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 8 Jan 2021 08:45:48 +0000 (17:45 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 14 Jan 2021 04:55:39 +0000 (04:55 +0000)
Change-Id: Ifee4762f873e5b239878988cf89541844b244394
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/pkgmgr_interface.cc
src/common/pkgmgr_interface.h
test/smoke_tests/common/smoke_utils.cc
test/smoke_tests/common/smoke_utils.h

index ed46880..3586684 100644 (file)
@@ -80,7 +80,7 @@ bool PkgmgrInstaller::ShouldCreateSignal() const {
 
 PkgMgrPtr PkgMgrInterface::Create(int argc, char** argv,
     PkgmgrInstallerInterface* pkgmgr_installer_interface,
-    AppQueryInterface* interface) {
+    std::shared_ptr<AppQueryInterface> interface) {
   PkgMgrPtr instance(new PkgMgrInterface(pkgmgr_installer_interface,
                                          interface));
   int result = instance->InitInternal(argc, argv);
@@ -148,7 +148,7 @@ bool PkgMgrInterface::SetAppQueryInterface(int idx) {
 }
 
 void PkgMgrInterface::AddAppQueryInterface(
-    int idx, AppQueryInterface* interface) {
+    int idx, std::shared_ptr<AppQueryInterface> interface) {
   query_interface_map_.emplace(idx, interface);
 }
 
@@ -171,7 +171,7 @@ RequestType PkgMgrInterface::GetRequestType(int idx) const {
       return RequestType::Move;
   }
 
-  AppQueryInterface* query_interface = query_interface_;
+  std::shared_ptr<AppQueryInterface> query_interface = query_interface_;
   if (!query_interface) {
     auto it = query_interface_map_.find(idx);
     if (it == query_interface_map_.end())
index 2c7f205..71b40f0 100644 (file)
@@ -80,7 +80,7 @@ class PkgMgrInterface {
    * \param idx index of request
    * \param interface AppQueryInterface for request
    */
-  void AddAppQueryInterface(int idx, AppQueryInterface* interface);
+  void AddAppQueryInterface(int idx, std::shared_ptr<AppQueryInterface> interface);
 
   /**
    * Returns Request type passed from pkgmgr_installer
@@ -120,7 +120,7 @@ class PkgMgrInterface {
    */
   static PkgMgrPtr Create(int argc, char** argv,
         PkgmgrInstallerInterface* pkgmgr_installer_interface,
-        AppQueryInterface* interface = nullptr);
+        std::shared_ptr<AppQueryInterface> interface = nullptr);
 
   /**
   * Returns TEP path passed from pkgmgr_installer
@@ -256,7 +256,7 @@ class PkgMgrInterface {
 
  private:
   explicit PkgMgrInterface(PkgmgrInstallerInterface* pkgmgr_installer_interface,
-                           AppQueryInterface* interface)
+                           std::shared_ptr<AppQueryInterface> interface)
       : pi_(nullptr),
         install_mode_(InstallationMode::ONLINE),
         is_app_installed_(boost::none),
@@ -269,8 +269,8 @@ class PkgMgrInterface {
   mutable boost::optional<bool> is_app_installed_;
   PkgmgrInstallerInterface* pkgmgr_installer_interface_;
 
-  AppQueryInterface* query_interface_;
-  std::map<int, AppQueryInterface*> query_interface_map_;
+  std::shared_ptr<AppQueryInterface> query_interface_;
+  std::map<int, std::shared_ptr<AppQueryInterface>> query_interface_map_;
 
   SCOPE_LOG_TAG(PkgMgrInterface)
   DISALLOW_COPY_AND_ASSIGN(PkgMgrInterface);
index 75ce7eb..db141c5 100644 (file)
@@ -594,12 +594,12 @@ bool CheckSharedDataNonExistance(const std::string& pkgid,
 void BackendInterface::TestRollbackAfterEachStep(int argc, const char* argv[],
     std::function<bool()> validator) const {
   TestPkgmgrInstaller pkgmgr_installer;
-  std::unique_ptr<ci::AppQueryInterface> query_interface =
+  std::shared_ptr<ci::AppQueryInterface> query_interface =
       CreateQueryInterface();
   auto pkgmgr =
       ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
                                   &pkgmgr_installer,
-                                  query_interface.get());
+                                  query_interface);
   if (!pkgmgr) {
     LOG(ERROR) << "Failed to initialize pkgmgr interface";
     return;
@@ -628,7 +628,7 @@ void BackendInterface::CrashAfterEachStep(std::vector<std::string>* args,
   auto pkgmgr =
       ci::PkgMgrInterface::Create(args->size(), const_cast<char**>(argv.get()),
                                   &pkgmgr_installer,
-                                  query_interface.get());
+                                  query_interface);
   if (!pkgmgr) {
     LOG(ERROR) << "Failed to initialize pkgmgr interface";
     return;
@@ -770,7 +770,7 @@ BackendInterface::CommandResult BackendInterface::CallBackend(int argc,
   TestPkgmgrInstaller pkgmgr_installer;
   auto query_interface = CreateQueryInterface();
   auto pkgmgr = ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
-      &pkgmgr_installer, query_interface.get());
+      &pkgmgr_installer, query_interface);
   if (!pkgmgr) {
     LOG(ERROR) << "Failed to initialize pkgmgr interface";
     return BackendInterface::CommandResult::UNKNOWN;
index 19efc71..3121b41 100644 (file)
@@ -285,7 +285,7 @@ class BackendInterface {
   CommandResult CallBackend(int argc, const char* argv[]) const;
   CommandResult CallBackendWithRunner(int argc, const char* argv[]) const;
   using AppQueryInterfacePtr =
-      std::unique_ptr<common_installer::AppQueryInterface>;
+      std::shared_ptr<common_installer::AppQueryInterface>;
   using AppInstallerPtr = std::unique_ptr<common_installer::AppInstaller>;
   SmokeInstallerFactoryPtr factory_;
   std::string uid_str_;