Fix leak and worng calling after release 77/268877/2
authorSukhyungKang <shine.kang@samsung.com>
Tue, 4 Jan 2022 06:09:53 +0000 (15:09 +0900)
committerSukhyungKang <shine.kang@samsung.com>
Tue, 4 Jan 2022 07:28:34 +0000 (16:28 +0900)
Change-Id: Iedda3416910a1a9f89b40ecd77ac7069e4aeb70e
Signed-off-by: SukhyungKang <shine.kang@samsung.com>
parser/widget_plugin_parser_db.c
src/widget_service.c

index ecdf5c8..9095720 100644 (file)
@@ -270,6 +270,7 @@ static int _insert_widget_class(sqlite3 *db, const char *pkgid, GList *wcs)
                ret = sqlite3_step(stmt);
                if (ret != SQLITE_DONE) {
                        LOGE("step error: %s", sqlite3_errmsg(db));
+                       ret = -1;
                        break;
                }
 
@@ -277,18 +278,28 @@ static int _insert_widget_class(sqlite3 *db, const char *pkgid, GList *wcs)
                sqlite3_clear_bindings(stmt);
 
                if (_insert_support_size(db, pkgid, wc->classid,
-                                       wc->support_size))
-                       return -1;
-               if (_insert_label(db, wc->classid, wc->label))
-                       return -1;
-               if (_insert_icon(db, pkgid, wc->classid, wc->icon))
-                       return -1;
+                                       wc->support_size)) {
+                       LOGE("Failed to insert support size");
+                       ret = -1;
+                       break;
+               }
+               if (_insert_label(db, wc->classid, wc->label)) {
+                       LOGE("Failed to insert label");
+                       ret = -1;
+                       break;
+               }
+               if (_insert_icon(db, pkgid, wc->classid, wc->icon)) {
+                       LOGE("Failed to insert icon");
+                       ret = -1;
+                       break;
+               }
+               ret = 0;
        }
 
        if (stmt)
                sqlite3_finalize(stmt);
 
-       return 0;
+       return ret;
 }
 
 int widget_parser_db_insert_widget_class(const char *pkgid, GList *widget_list)
index d055538..ecd772d 100644 (file)
@@ -1291,8 +1291,6 @@ static char *_get_main_app_id(const char *widget_id, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
-               sqlite3_finalize(stmt);
-               sqlite3_close_v2(db);
                /* TODO: which error should be set? */
                if (ret == SQLITE_DONE) {
                        set_last_result(WIDGET_ERROR_NOT_EXIST);
@@ -1300,6 +1298,8 @@ static char *_get_main_app_id(const char *widget_id, uid_t uid)
                        set_last_result(WIDGET_ERROR_FAULT);
                        _E("step error: %s", sqlite3_errmsg(db));
                }
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
                return NULL;
        }
 
@@ -1436,8 +1436,6 @@ static char *_get_app_id_of_setup_app(const char *widget_id, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
-               sqlite3_finalize(stmt);
-               sqlite3_close_v2(db);
                /* TODO: which error should be set? */
                if (ret == SQLITE_DONE) {
                        set_last_result(WIDGET_ERROR_NOT_EXIST);
@@ -1445,6 +1443,8 @@ static char *_get_app_id_of_setup_app(const char *widget_id, uid_t uid)
                        set_last_result(WIDGET_ERROR_FAULT);
                        _E("step error: %s", sqlite3_errmsg(db));
                }
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
                return NULL;
        }
 
@@ -1520,8 +1520,6 @@ static int _get_nodisplay(const char *widget_id, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
-               sqlite3_finalize(stmt);
-               sqlite3_close_v2(db);
                /* TODO: which error should be set? */
                if (ret == SQLITE_DONE) {
                        set_last_result(WIDGET_ERROR_NOT_EXIST);
@@ -1529,6 +1527,8 @@ static int _get_nodisplay(const char *widget_id, uid_t uid)
                        set_last_result(WIDGET_ERROR_FAULT);
                        _E("step error: %s", sqlite3_errmsg(db));
                }
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
                return 0;
        }
 
@@ -1566,14 +1566,15 @@ static int _get_update_period(const char *widget_id, uid_t uid, double *period)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
-               sqlite3_finalize(stmt);
-               sqlite3_close_v2(db);
                if (ret == SQLITE_DONE) {
-                       return WIDGET_ERROR_NOT_EXIST;
+                       ret = WIDGET_ERROR_NOT_EXIST;
                } else {
                        _E("step error: %s", sqlite3_errmsg(db));
-                       return WIDGET_ERROR_FAULT;
+                       ret = WIDGET_ERROR_FAULT;
                }
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
+               return ret;
        }
 
        _get_column_double(stmt, 0, period);
@@ -1729,8 +1730,6 @@ static char *_get_preview_image_path(const char *widget_id, int width,
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
-               sqlite3_finalize(stmt);
-               sqlite3_close_v2(db);
                /* TODO: which error should be set? */
                if (ret == SQLITE_DONE) {
                        set_last_result(WIDGET_ERROR_NOT_EXIST);
@@ -1738,6 +1737,8 @@ static char *_get_preview_image_path(const char *widget_id, int width,
                        set_last_result(WIDGET_ERROR_FAULT);
                        _E("step error: %s", sqlite3_errmsg(db));
                }
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
                return NULL;
        }
 
@@ -2402,8 +2403,6 @@ static char *_get_package_id(const char *widget_id, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
-               sqlite3_finalize(stmt);
-               sqlite3_close_v2(db);
                /* TODO: which error should be set? */
                if (ret == SQLITE_DONE) {
                        set_last_result(WIDGET_ERROR_NOT_EXIST);
@@ -2411,6 +2410,8 @@ static char *_get_package_id(const char *widget_id, uid_t uid)
                        set_last_result(WIDGET_ERROR_FAULT);
                        _E("step error: %s", sqlite3_errmsg(db));
                }
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
                return NULL;
        }
 
@@ -2731,14 +2732,15 @@ static int __get_max_instance(const char *widget_id, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
-               sqlite3_finalize(stmt);
-               sqlite3_close_v2(db);
                if (ret == SQLITE_DONE) {
-                       return WIDGET_ERROR_NOT_EXIST;
+                       ret = WIDGET_ERROR_NOT_EXIST;
                } else {
                        _E("step error: %s", sqlite3_errmsg(db));
-                       return WIDGET_ERROR_FAULT;
+                       ret = WIDGET_ERROR_FAULT;
                }
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
+               return ret;
        }
 
        _get_column_int(stmt, 0, &max_instance);
@@ -2860,15 +2862,16 @@ static int _get_disable(const char *widget_id, bool *is_disabled, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
-               sqlite3_free(query);
-               sqlite3_finalize(stmt);
-               sqlite3_close_v2(db);
                if (ret == SQLITE_DONE) {
-                       return WIDGET_ERROR_NOT_EXIST;
+                       ret = WIDGET_ERROR_NOT_EXIST;
                } else {
                        _E("step error: %s, %d", sqlite3_errmsg(db), ret);
-                       return WIDGET_ERROR_FAULT;
+                       ret = WIDGET_ERROR_FAULT;
                }
+               sqlite3_free(query);
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
+               return ret;
        }
        _get_column_int(stmt, 0, &disable);