Fix memory leak 02/126002/3 accepted/tizen/3.0/common/20170508.152937 accepted/tizen/3.0/ivi/20170508.050220 accepted/tizen/3.0/mobile/20170508.050133 accepted/tizen/3.0/tv/20170508.050153 accepted/tizen/3.0/wearable/20170508.050205 submit/tizen_3.0-common/20170508.080135 submit/tizen_3.0-common/20170508.081301 submit/tizen_3.0-common/20170508.091535 submit/tizen_3.0/20170420.011011 submit/tizen_3.0_common/20170508.091735
authorSeungha Son <seungha.son@samsung.com>
Tue, 18 Apr 2017 02:07:49 +0000 (11:07 +0900)
committerSeungha Son <seungha.son@samsung.com>
Thu, 20 Apr 2017 00:38:41 +0000 (09:38 +0900)
Signed-off-by: Seungha Son <seungha.son@samsung.com>
Change-Id: Ia3e0492274d585781bf0a05e7b539bea48c44d89
Signed-off-by: jusung son <jusung07.son@samsung.com>
src/notification_noti.c

index 07b6b62..1845833 100755 (executable)
@@ -22,6 +22,7 @@
 #include <pkgmgr-info.h>
 #include <package_manager.h>
 #include <app_control_internal.h>
+#include <bundle_internal.h>
 
 #include <notification.h>
 #include <notification_internal.h>
@@ -348,6 +349,11 @@ static int _insertion_query_create(notification_h noti, char **query)
        if (b_service_multi_launch)
                free(b_service_multi_launch);
 
+       for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
+               if (b_event_handler[i])
+                       bundle_free_encoded_rawdata((bundle_raw **)&b_event_handler[i]);
+       }
+
        if (b_text)
                free(b_text);
 
@@ -522,6 +528,11 @@ static int _update_query_create(notification_h noti, char **query)
        if (b_service_multi_launch)
                free(b_service_multi_launch);
 
+       for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
+               if (b_event_handler[i])
+                       bundle_free_encoded_rawdata((bundle_raw **)&b_event_handler[i]);
+       }
+
        if (b_text)
                free(b_text);
 
@@ -1132,7 +1143,8 @@ EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname,
                         "from noti_list where caller_pkgname = ? and tag = ? and uid = ?", -1, &stmt, NULL);
                if (ret != SQLITE_OK) {
                        NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
-                       return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                       goto err;
                }
 
                ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
@@ -1168,7 +1180,8 @@ EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname,
                         "from noti_list where  tag = ? and uid = ?", -1, &stmt, NULL);
                if (ret != SQLITE_OK) {
                        NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
-                       return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                       goto err;
                }
 
                ret = sqlite3_bind_text(stmt, 1, tag, -1, SQLITE_TRANSIENT);
@@ -1215,10 +1228,6 @@ EXPORT_API int notification_noti_update(notification_h noti)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
 
-       db = notification_db_open(DBPATH);
-       if (!db)
-               return get_last_result();
-
        if (_is_allowed_to_notify(noti) == false) {
                NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
                return NOTIFICATION_ERROR_PERMISSION_DENIED;
@@ -1232,6 +1241,10 @@ EXPORT_API int notification_noti_update(notification_h noti)
                NOTIFICATION_DBG("notification display applist - pkgname [%s], applist [%d]", noti->caller_pkgname, noti->display_applist);
        }
 
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
+
        /* Check private ID is exist */
        ret = _notification_noti_check_priv_id(noti, db);
        if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
@@ -1838,7 +1851,6 @@ EXPORT_API int notification_noti_check_tag(notification_h noti)
        else
                result = 0;
 
-       sqlite3_finalize(stmt);
 
        /* If result > 0, there is priv_id in DB */
        if (result > 0) {
@@ -1849,6 +1861,8 @@ EXPORT_API int notification_noti_check_tag(notification_h noti)
        }
 
 err:
+       if (stmt != NULL)
+               sqlite3_finalize(stmt);
        if (db)
                notification_db_close(&db);
 
@@ -1891,8 +1905,9 @@ EXPORT_API int notification_noti_check_count_for_template(notification_h noti, i
 
        *count = result;
 
-       sqlite3_finalize(stmt);
 err:
+       if (stmt != NULL)
+               sqlite3_finalize(stmt);
        if (db)
                notification_db_close(&db);
 
@@ -2073,6 +2088,11 @@ static int _template_query_create(notification_h noti, char *template_name, char
        if (b_service_multi_launch)
                free(b_service_multi_launch);
 
+       for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
+               if (b_event_handler[i])
+                       bundle_free_encoded_rawdata((bundle_raw **)&b_event_handler[i]);
+       }
+
        if (b_text)
                free(b_text);