Fix coverity issues 27/178227/1 accepted/tizen/unified/20180509.073103 submit/tizen/20180509.022227
authorseolheui kim <s414.kim@samsung.com>
Wed, 9 May 2018 01:41:27 +0000 (10:41 +0900)
committerseolheui kim <s414.kim@samsung.com>
Wed, 9 May 2018 01:41:27 +0000 (10:41 +0900)
- fix resource memory leak
- fix unchecked return value

Change-Id: Ib8cd70fcc0c995c4c753ce5b86599854ddba82e2
Signed-off-by: seolheui kim <s414.kim@samsung.com>
ode/src/interface/tools/battery.cpp
ode/src/widgets/appcontrol.cpp
ode/src/widgets/notification.cpp
secure-erase/src/ui.c

index daa0d941f6be950894111e002cc2042d91214590..9c2213b3166fbc8572df107682054467ea8e03be 100644 (file)
@@ -47,7 +47,11 @@ Battery::~Battery()
 bool Battery::getChargerConnected()
 {
        bool connected = false;
-       ::runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &connected);
+
+       if (::runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &connected)
+                       != RUNTIME_INFO_ERROR_NONE)
+               return false;
+
        return connected;
 }
 
index 80f1ecfc96a46745ac667e1554eee0adff6a1bdc..531db0bcf3e8ae97536500684162e02d32cdf44c 100644 (file)
@@ -45,6 +45,9 @@ AppControl::~AppControl()
 {
        if (appControl != nullptr)
                ::app_control_destroy(appControl);
+
+       if (caller != nullptr)
+               ::app_control_destroy(caller);
 }
 
 AppControl::operator app_control_h()
index 92da321c6d5dc897ba2d740413d0304d293b30f7..694c8348537dfd66de11d2188a73334c27bec485 100644 (file)
@@ -15,7 +15,7 @@
  * limitations under the License.
  *
  */
-
+#include <dlog.h>
 #include "notification.h"
 
 Notification::Notification(notification_type_e type)
@@ -31,19 +31,25 @@ Notification::~Notification()
 
 void Notification::setTitle(const std::string &title)
 {
-       ::notification_set_text(notification, NOTIFICATION_TEXT_TYPE_TITLE,
+       int ret = ::notification_set_text(notification, NOTIFICATION_TEXT_TYPE_TITLE,
                                                        title.c_str(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       if (ret != NOTIFICATION_ERROR_NONE)
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set title text to notification");
 }
 
 void Notification::setContentText(const std::string &content)
 {
-       ::notification_set_text(notification, NOTIFICATION_TEXT_TYPE_CONTENT,
+       int ret = ::notification_set_text(notification, NOTIFICATION_TEXT_TYPE_CONTENT,
                                                        content.c_str(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       if (ret != NOTIFICATION_ERROR_NONE)
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set content text to notification");
 }
 
 void Notification::setProgress(double value)
 {
-       ::notification_set_progress(notification, value);
+       if (::notification_set_progress(notification, value)
+                       != NOTIFICATION_ERROR_NONE)
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set progress to notification");
 }
 
 double Notification::getProgress()
@@ -55,27 +61,33 @@ double Notification::getProgress()
 
 void Notification::setLayout(notification_ly_type_e type)
 {
-       ::notification_set_layout(notification, type);
+       if (::notification_set_layout(notification, type) != NOTIFICATION_ERROR_NONE)
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set layout to notification");
 }
 
 void Notification::setImage(const std::string &path)
 {
-       ::notification_set_image(notification, NOTIFICATION_IMAGE_TYPE_THUMBNAIL, path.c_str());
+       if (::notification_set_image(notification, NOTIFICATION_IMAGE_TYPE_THUMBNAIL, path.c_str()) != NOTIFICATION_ERROR_NONE)
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set image to notification");
 }
 
 void Notification::setAppControl(AppControl &appControl)
 {
-       ::notification_set_launch_option(notification, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, appControl);
+       if (::notification_set_launch_option(notification, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, appControl)
+                       != NOTIFICATION_ERROR_NONE)
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set launch option to notification");
 }
 
 void Notification::update()
 {
-       ::notification_update(notification);
+       if (::notification_update(notification) != NOTIFICATION_ERROR_NONE)
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to update notification");
 }
 
 void Notification::post()
 {
-       ::notification_post(notification);
+       if (::notification_post(notification) != NOTIFICATION_ERROR_NONE)
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to post notification");
 }
 
 void Notification::dispose()
index 216482f70a3e17bd661149102b6091563ecda3bb..6cf2fa3327b60ddf66f11010bebd6293751d1c8b 100644 (file)
@@ -33,25 +33,33 @@ static notification_h add_notification(notification_type_e type, const char *tit
 
        if (title) {
                ret = notification_set_text(handle, NOTIFICATION_TEXT_TYPE_TITLE, title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-               if (ret != NOTIFICATION_ERROR_NONE)
+               if (ret != NOTIFICATION_ERROR_NONE) {
+                       notification_free(handle);
                        return NULL;
+               }
        }
 
        if (content) {
                ret = notification_set_text(handle, NOTIFICATION_TEXT_TYPE_CONTENT, content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-               if (ret != NOTIFICATION_ERROR_NONE)
+               if (ret != NOTIFICATION_ERROR_NONE) {
+                       notification_free(handle);
                        return NULL;
+               }
        }
 
        if (image) {
                ret = notification_set_image(handle, NOTIFICATION_IMAGE_TYPE_THUMBNAIL, image);
-               if (ret != NOTIFICATION_ERROR_NONE)
+               if (ret != NOTIFICATION_ERROR_NONE) {
+                       notification_free(handle);
                        return NULL;
+               }
        }
 
        ret = notification_set_layout(handle, layout);
-       if (ret != NOTIFICATION_ERROR_NONE)
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               notification_free(handle);
                return NULL;
+       }
 
        return handle;
 }