[Application][Alarm] Free app_control_h using app_control_destroy 17/136117/2
authorLukasz Bardeli <l.bardeli@samsung.com>
Wed, 28 Jun 2017 06:24:32 +0000 (08:24 +0200)
committerLukasz Bardeli <l.bardeli@samsung.com>
Wed, 28 Jun 2017 06:35:38 +0000 (06:35 +0000)
[Verification] Code compiles without error. TCT passrate
               Alarm 100%
               AppControl 100%
               Application 100%

Change-Id: I5c32e2307d9b7e8b36df0919c670c97b5828a572

src/alarm/alarm_utils.cc
src/application/application_utils.cc

index 1c9ee9d58b824d9829ac2c7c85613258ce41cea3..ba8872c3d7c47ea72653d0ac5ec1866b8010c8ad 100755 (executable)
@@ -14,6 +14,8 @@
  *    limitations under the License.
  */
 
+#include <memory>
+
 #include "alarm_utils.h"
 
 #include "common/logger.h"
@@ -34,9 +36,19 @@ PlatformResult AppControlToService(const picojson::object& obj, app_control_h *a
     return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed.");
   }
 
-  app_control_create(app_control);
+  app_control_h app_control_tmp = nullptr;
+  int result = app_control_create(&app_control_tmp);
+
+  if (APP_CONTROL_ERROR_NONE != result) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Creation AppControl failed.",
+                             ("Problem with create handle."));
+  }
+
+  std::unique_ptr<std::remove_pointer<app_control_h>::type, int(*)(app_control_h)> app_control_ptr(
+      app_control_tmp, &app_control_destroy);
+
 
-  int ret = app_control_set_operation(*app_control, it_operation->second.get<std::string>().c_str());
+  int ret = app_control_set_operation(app_control_tmp, it_operation->second.get<std::string>().c_str());
   if (APP_CONTROL_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error while setting operation.",
                               ("Failed app_control_set_operation(): %d (%s)", ret, get_error_message(ret)));
@@ -44,7 +56,7 @@ PlatformResult AppControlToService(const picojson::object& obj, app_control_h *a
 
   const auto it_uri = obj.find("uri");
   if (it_end != it_uri && it_uri->second.is<std::string>()) {
-    ret = app_control_set_uri(*app_control, it_uri->second.get<std::string>().c_str());
+    ret = app_control_set_uri(app_control_tmp, it_uri->second.get<std::string>().c_str());
     if (APP_CONTROL_ERROR_NONE != ret) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error while setting uri.",
                                 ("Failed app_control_set_uri(): %d (%s)", ret, get_error_message(ret)));
@@ -53,7 +65,7 @@ PlatformResult AppControlToService(const picojson::object& obj, app_control_h *a
 
   const auto it_mime = obj.find("mime");
   if (it_end != it_mime && it_mime->second.is<std::string>()) {
-    ret = app_control_set_mime(*app_control, it_mime->second.get<std::string>().c_str());
+    ret = app_control_set_mime(app_control_tmp, it_mime->second.get<std::string>().c_str());
     if (APP_CONTROL_ERROR_NONE != ret) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error while setting mime.",
                                 ("Failed app_control_set_mime(): %d (%s)", ret, get_error_message(ret)));
@@ -62,7 +74,7 @@ PlatformResult AppControlToService(const picojson::object& obj, app_control_h *a
 
   const auto it_category = obj.find("category");
   if (it_end != it_category && it_category->second.is<std::string>()) {
-    ret = app_control_set_category(*app_control, it_category->second.get<std::string>().c_str());
+    ret = app_control_set_category(app_control_tmp, it_category->second.get<std::string>().c_str());
     if (APP_CONTROL_ERROR_NONE != ret) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error while setting category.",
                                 ("Failed app_control_set_category(): %d (%s)", ret, get_error_message(ret)));
@@ -75,7 +87,7 @@ PlatformResult AppControlToService(const picojson::object& obj, app_control_h *a
     PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
 
     for (auto iter = data.begin(); iter != data.end(); ++iter) {
-      result = AppControlToServiceExtraData(iter->get<picojson::object>(), app_control);
+      result = AppControlToServiceExtraData(iter->get<picojson::object>(), &app_control_tmp);
       if (!result) {
         LoggerE("Failed AppControlToServiceExtraData()");
         return result;
@@ -83,6 +95,8 @@ PlatformResult AppControlToService(const picojson::object& obj, app_control_h *a
     }
   }
 
+  *app_control = app_control_ptr.release();
+
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
index a7860c1e427eb0e8a8265703d857929eb9403754..8d56999c96738668900444c0a2d13487965cf6f6 100644 (file)
@@ -207,24 +207,33 @@ PlatformResult ApplicationUtils::ApplicationControlToService(
     return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter was passed.");
   }
 
-  app_control_create(app_control);
+  app_control_h app_control_tmp = nullptr;
+  int result = app_control_create(&app_control_tmp);
+
+  if (APP_CONTROL_ERROR_NONE != result) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Creation AppControl failed.",
+                             ("Problem with create handle."));
+  }
+
+  std::unique_ptr<std::remove_pointer<app_control_h>::type, int(*)(app_control_h)> app_control_ptr(
+      app_control_tmp, &app_control_destroy);
 
   // operation
-  app_control_set_operation(*app_control, it_operation->second.get<std::string>().c_str());
+  app_control_set_operation(app_control_tmp, it_operation->second.get<std::string>().c_str());
 
   // uri
   if (it_uri->second.is<std::string>()) {
-    app_control_set_uri(*app_control, it_uri->second.get<std::string>().c_str());
+    app_control_set_uri(app_control_tmp, it_uri->second.get<std::string>().c_str());
   }
 
   // mime
   if (it_mime->second.is<std::string>()) {
-    app_control_set_mime(*app_control, it_mime->second.get<std::string>().c_str());
+    app_control_set_mime(app_control_tmp, it_mime->second.get<std::string>().c_str());
   }
 
   // category
   if (it_category->second.is<std::string>()) {
-    app_control_set_category(*app_control, it_category->second.get<std::string>().c_str());
+    app_control_set_category(app_control_tmp, it_category->second.get<std::string>().c_str());
   }
 
   // ApplicationControlData
@@ -233,7 +242,7 @@ PlatformResult ApplicationUtils::ApplicationControlToService(
   for (auto iter = data.begin(); iter != data.end(); ++iter) {
     if (iter->is<picojson::object>()) {
       PlatformResult ret =
-          ApplicationControlDataToServiceExtraData(iter->get<picojson::object>(), *app_control);
+          ApplicationControlDataToServiceExtraData(iter->get<picojson::object>(), app_control_tmp);
       if (ret.IsError()) {
         LoggerE("Failed ApplicationControlDataToServiceExtraData()");
         return ret;
@@ -241,6 +250,8 @@ PlatformResult ApplicationUtils::ApplicationControlToService(
     }
   }
 
+  *app_control = app_control_ptr.release();
+
   return PlatformResult(ErrorCode::NO_ERROR);
 }