[Notification] - fixing memory deallocation bugs reported by prevent
authorAndrzej Popowski <a.popowski@samsung.com>
Tue, 9 Jun 2015 11:56:35 +0000 (13:56 +0200)
committerAndrzej Popowski <a.popowski@samsung.com>
Tue, 9 Jun 2015 12:42:14 +0000 (14:42 +0200)
Change-Id: I16efd559297c2caa8791ce9d96a1cfae28725bbe
Signed-off-by: Andrzej Popowski <a.popowski@samsung.com>
src/notification/notification_manager.cc
src/notification/status_notification.cc

index ca6f4cd91f31187c52b774b4b2adc804be4045a4..c45a19fe13273453d4fe6def2936981bad93e855 100644 (file)
@@ -94,6 +94,7 @@ PlatformResult NotificationManager::Get(const picojson::object& args,
   LoggerD("Enter");
   int id = std::stoi(FromJson<std::string>(args, "id"));
 
+  app_control_h app_control = nullptr;
   notification_h noti_handle;
   PlatformResult status = StatusNotification::GetNotiHandle(id, &noti_handle);
   if (status.IsError())
@@ -101,7 +102,14 @@ PlatformResult NotificationManager::Get(const picojson::object& args,
     LoggerE("Failed: GetNotiHandle");
     return status;
   }
-  app_control_h app_control;
+
+  SCOPE_EXIT {
+    if (app_control) {
+      app_control_destroy(app_control);
+    }
+    free(noti_handle);
+  };
+
   status = StatusNotification::GetAppControl(noti_handle, &app_control);
   if (status.IsError())
   {
index 64eb984c094055b0224910238a61b8ff3da0f6ca..c523a2735ba41b03b2285de98658de186411a3ac 100644 (file)
@@ -1167,6 +1167,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
   int ret;
 
   notification_h noti_handle;
+  app_control_h app_control = NULL;
   if (is_update) {
     id = std::stoi(common::FromJson<std::string>(noti_obj, "id"));
 
@@ -1180,25 +1181,35 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
       return status;
   }
 
+  SCOPE_EXIT {
+    if (app_control) {
+      app_control_destroy(app_control);
+    }
+    free(noti_handle);
+  };
+
   status = SetLayout(noti_handle, status_type);
-  if (status.IsError())
+  if (status.IsError()) {
     return status;
+  }
 
   picojson::value val(noti_obj);
   if (val.contains("iconPath") && !IsNull(noti_obj, "iconPath")) {
     const std::string& value_str =
         common::FromJson<std::string>(noti_obj, "iconPath");
     status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, value_str);
-    if (status.IsError())
+    if (status.IsError()) {
       return status;
+    }
   }
 
   if (val.contains("subIconPath") && !IsNull(noti_obj, "subIconPath")) {
     const std::string& value_str =
         common::FromJson<std::string>(noti_obj, "subIconPath");
     status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, value_str);
-    if (status.IsError())
+    if (status.IsError()) {
       return status;
+    }
   }
 
   if (val.contains("number") && !IsNull(noti_obj, "number")) {
@@ -1206,35 +1217,40 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
         std::to_string(common::FromJson<double>(noti_obj, "number"));
     status =
         SetText(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, value_str);
-    if (status.IsError())
+    if (status.IsError()) {
       return status;
+    }
   }
 
   if (val.contains("detailInfo") && !IsNull(noti_obj, "detailInfo")) {
     status = SetDetailInfos(
         noti_handle, common::FromJson<picojson::array>(noti_obj, "detailInfo"));
-    if (status.IsError())
+    if (status.IsError()) {
       return status;
+    }
   }
 
   if (val.contains("ledColor") && !IsNull(noti_obj, "ledColor")) {
     status = SetLedColor(noti_handle,
                          common::FromJson<std::string>(noti_obj, "ledColor"));
-    if (status.IsError())
+    if (status.IsError()) {
       return status;
+    }
   }
 
   status = SetLedOnPeriod(noti_handle,
                           static_cast<unsigned long>(common::FromJson<double>(
                               noti_obj, "ledOnPeriod")));
-  if (status.IsError())
+  if (status.IsError()) {
     return status;
+  }
 
   status = SetLedOffPeriod(noti_handle,
                            static_cast<unsigned long>(common::FromJson<double>(
                                noti_obj, "ledOffPeriod")));
-  if (status.IsError())
+  if (status.IsError()) {
     return status;
+  }
 
   if (val.contains("backgroundImagePath")
       && !IsNull(noti_obj, "backgroundImagePath")) {
@@ -1242,47 +1258,53 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
         common::FromJson<std::string>(noti_obj, "backgroundImagePath");
     status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_BACKGROUND,
         value_str);
-    if (status.IsError())
+    if (status.IsError()) {
       return status;
+    }
   }
 
   if (val.contains("thumbnails") && !IsNull(noti_obj, "thumbnails")) {
     status = SetThumbnails(
         noti_handle, common::FromJson<picojson::array>(noti_obj, "thumbnails"));
-    if (status.IsError())
+    if (status.IsError()) {
       return status;
+    }
   }
 
   if (val.contains("soundPath") && !IsNull(noti_obj, "soundPath")) {
     status = SetSoundPath(noti_handle,
                           common::FromJson<std::string>(noti_obj, "soundPath"));
-    if (status.IsError())
+    if (status.IsError()) {
       return status;
+    }
   }
 
   status =
       SetVibration(noti_handle, common::FromJson<bool>(noti_obj, "vibration"));
-  if (status.IsError())
+  if (status.IsError()) {
     return status;
+  }
 
-  app_control_h app_control = NULL;
   status = CreateAppControl(&app_control);
-  if (status.IsError())
+  if (status.IsError()) {
     return status;
+  }
 
   if (val.contains("appControl") && !IsNull(noti_obj, "appControl")) {
     status = SetApplicationControl(
         app_control,
         common::FromJson<picojson::object>(noti_obj, "appControl"));
-    if (status.IsError())
+    if (status.IsError()) {
       return status;
+    }
   }
 
   if (val.contains("appId") && !IsNull(noti_obj, "appId")) {
     status = SetApplicationId(app_control,
                               common::FromJson<std::string>(noti_obj, "appId"));
-    if (status.IsError())
+    if (status.IsError()) {
       return status;
+    }
   }
 
   const std::string& progress_type =
@@ -1297,22 +1319,25 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
     status = SetProgressValue(noti_handle, progress_type, progressValue,
         is_update);
 
-    if (status.IsError())
+    if (status.IsError()) {
       return status;
+    }
   }
 
   status = SetText(noti_handle,
                    NOTIFICATION_TEXT_TYPE_TITLE,
                    common::FromJson<std::string>(noti_obj, "title"));
-  if (status.IsError())
+  if (status.IsError()) {
     return status;
+  }
 
   if (val.contains("content") && !IsNull(noti_obj, "content")) {
     status = SetText(noti_handle,
                      NOTIFICATION_TEXT_TYPE_CONTENT,
                      common::FromJson<std::string>(noti_obj, "content"));
-    if (status.IsError())
+    if (status.IsError()) {
       return status;
+    }
   }
 
   status = SetAppControl(noti_handle, app_control);
@@ -1335,8 +1360,9 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
 
   time_t posted_time;
   status = GetPostedTime(noti_handle, &posted_time);
-  if (status.IsError())
+  if (status.IsError()) {
     return status;
+  }
 
   if (is_update) {
     return PlatformResult(ErrorCode::NO_ERROR);