[Package] Fixed memory leak.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Mon, 24 Aug 2015 09:25:03 +0000 (11:25 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Mon, 24 Aug 2015 09:40:35 +0000 (18:40 +0900)
Prevent CID: 435873

[Verification] TCT pass rate (r35): 100% (54/54/0/0/0)

Change-Id: I9259991af7b1dd45c6b6ae57782ff6ce2dc5fa0b
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/package/package_info_provider.cc

index 557293e1643e7ecb01a920c536e342766e25df6b..9f41455f9f7a1d57dcfd4c11f5124de441e2ba62 100644 (file)
@@ -27,6 +27,7 @@
 #include <functional>
 
 #include "common/logger.h"
+#include "common/scope_exit.h"
 #include "common/tools.h"
 
 namespace extension {
@@ -218,6 +219,12 @@ bool PackageInfoProvider:: ConvertToPackageToObject(
     return false;
   }
 
+  SCOPE_EXIT {
+    if (PACKAGE_MANAGER_ERROR_NONE != package_info_destroy(package_info)) {
+      LoggerE("Failed to destroy package info");
+    }
+  };
+
   picojson::array array_data;
   ret = package_info_foreach_app_from_package(package_info,
       PACKAGE_INFO_ALLAPP, PackageAppInfoCb, &array_data);
@@ -227,11 +234,6 @@ bool PackageInfoProvider:: ConvertToPackageToObject(
   }
   out["appIds"] = picojson::value(array_data);
 
-  ret = package_info_destroy(package_info);
-  if ( ret != PACKAGE_MANAGER_ERROR_NONE ) {
-    LoggerE("Failed to destroy package info");
-  }
-
   return true;
 }