From 2b0054707f9005c53e18ff74fdd13e5ac4520be4 Mon Sep 17 00:00:00 2001 From: Andrzej Popowski Date: Tue, 9 Jun 2015 13:56:35 +0200 Subject: [PATCH] [Notification] - fixing memory deallocation bugs reported by prevent Change-Id: I16efd559297c2caa8791ce9d96a1cfae28725bbe Signed-off-by: Andrzej Popowski --- src/notification/notification_manager.cc | 10 +++- src/notification/status_notification.cc | 66 +++++++++++++++++------- 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/notification/notification_manager.cc b/src/notification/notification_manager.cc index ca6f4cd9..c45a19fe 100644 --- a/src/notification/notification_manager.cc +++ b/src/notification/notification_manager.cc @@ -94,6 +94,7 @@ PlatformResult NotificationManager::Get(const picojson::object& args, LoggerD("Enter"); int id = std::stoi(FromJson(args, "id")); + app_control_h app_control = nullptr; notification_h noti_handle; PlatformResult status = StatusNotification::GetNotiHandle(id, ¬i_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()) { diff --git a/src/notification/status_notification.cc b/src/notification/status_notification.cc index 64eb984c..c523a273 100644 --- a/src/notification/status_notification.cc +++ b/src/notification/status_notification.cc @@ -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(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(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(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(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(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(noti_obj, "ledColor")); - if (status.IsError()) + if (status.IsError()) { return status; + } } status = SetLedOnPeriod(noti_handle, static_cast(common::FromJson( noti_obj, "ledOnPeriod"))); - if (status.IsError()) + if (status.IsError()) { return status; + } status = SetLedOffPeriod(noti_handle, static_cast(common::FromJson( 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(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(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(noti_obj, "soundPath")); - if (status.IsError()) + if (status.IsError()) { return status; + } } status = SetVibration(noti_handle, common::FromJson(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(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(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(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(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); -- 2.34.1