Fix a memory leak 94/174494/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Mon, 2 Apr 2018 10:45:26 +0000 (19:45 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Mon, 2 Apr 2018 11:17:11 +0000 (11:17 +0000)
__BIND_TEXT macro cannot free local allocated variable.

Change-Id: Iaaa140efa0f14193bc40ddd33cd1a13aa8403cb6
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
parser/src/pkgmgr_parser_db.c

index 2b4fab1..6afd1da 100644 (file)
@@ -1005,6 +1005,9 @@ static GList *__find_splashscreens(GList *splashscreens)
        GList *list = NULL;
        splashscreen_x *ss;
 
+       if (splashscreens == NULL)
+               return NULL;
+
        g_list_foreach(splashscreens,
                        __find_appcontrol_splashscreen_with_dpi, &list);
        g_list_foreach(splashscreens,
@@ -1020,7 +1023,8 @@ static GList *__find_splashscreens(GList *splashscreens)
        return list;
 }
 
-static int __insert_splashscreen_info(sqlite3 *db, application_x *app)
+static int __insert_splashscreen_info(sqlite3 *db, application_x *app,
+               GList *ss_list)
 {
        static const char query[] =
                "INSERT INTO package_app_splash_screen (app_id, src, type,"
@@ -1031,19 +1035,16 @@ static int __insert_splashscreen_info(sqlite3 *db, application_x *app)
        int idx;
        GList *tmp;
        splashscreen_x *ss;
-       GList *ss_list;
 
        if (app->splashscreens == NULL)
                return 0;
 
-       ss_list = __find_splashscreens(app->splashscreens);
        if (ss_list == NULL)
                return 0;
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("prepare failed: %s", sqlite3_errmsg(db));
-               g_list_free(ss_list);
                return -1;
        }
 
@@ -1064,7 +1065,6 @@ static int __insert_splashscreen_info(sqlite3 *db, application_x *app)
                if (ret != SQLITE_DONE) {
                        _LOGE("step failed: %s", sqlite3_errmsg(db));
                        sqlite3_finalize(stmt);
-                       g_list_free(ss_list);
                        return -1;
                }
 
@@ -1072,7 +1072,6 @@ static int __insert_splashscreen_info(sqlite3 *db, application_x *app)
        }
 
        sqlite3_finalize(stmt);
-       g_list_free(ss_list);
 
        return 0;
 }
@@ -1671,6 +1670,7 @@ static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
        application_x *app;
        int bg_category;
        const char *effective_appid;
+       GList *ss_list;
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
@@ -1766,10 +1766,13 @@ static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
                        sqlite3_finalize(stmt);
                        return -1;
                }
-               if (__insert_splashscreen_info(db, app)) {
+               ss_list = __find_splashscreens(app->splashscreens);
+               if (__insert_splashscreen_info(db, app, ss_list)) {
+                       g_list_free(ss_list);
                        sqlite3_finalize(stmt);
                        return -1;
                }
+               g_list_free(ss_list);
                if (__insert_app_localized_info(db, app)) {
                        sqlite3_finalize(stmt);
                        return -1;