Fix memory leak 96/111596/2
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 23 Jan 2017 02:37:16 +0000 (11:37 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 23 Jan 2017 03:52:02 +0000 (12:52 +0900)
Change-Id: I4fe31da58dcee7baa4f3029470d37749a3a8de71
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/widget_instance.c
src/widget_service.c

index bf2e8a8..fe012e6 100644 (file)
@@ -244,8 +244,11 @@ static void __remove_instance(struct _widget_instance *instance)
                app->instances = g_list_remove(app->instances, instance);
                if (app->instances == NULL) {
                        _widget_apps = g_list_remove(_widget_apps, app);
+                       if (app->widget_id)
+                               free(app->widget_id);
+                       if (app->viewer_id)
+                               free(app->viewer_id);
                        free(app);
-                       app = NULL;
                }
        }
 
@@ -880,6 +883,10 @@ EAPI int widget_instance_init(const char *viewer_id)
 
 EAPI int widget_instance_fini()
 {
+       if (lifecycle_tbl) {
+               g_hash_table_destroy(lifecycle_tbl);
+               lifecycle_tbl = NULL;
+       }
 
        if (conn_viewer) {
                if (aul_app_com_leave(conn_viewer) < 0)
@@ -896,6 +903,11 @@ EAPI int widget_instance_fini()
                viewer_appid = NULL;
        }
 
+       if (package_id) {
+               free(package_id);
+               package_id = NULL;
+       }
+
        return 0;
 }
 
@@ -1128,6 +1140,18 @@ EAPI int widget_instance_unlisten_event(widget_instance_event_cb cb)
        return -1;
 }
 
+static void __destroy_lifecycle_local(gpointer data)
+{
+       struct lifecycle_local_s *cb_info = (struct lifecycle_local_s *)data;
+
+       if (cb_info == NULL)
+               return;
+
+       if (cb_info->widget_id)
+               free(cb_info->widget_id);
+       free(cb_info);
+}
+
 /* within package only */
 EAPI int widget_instance_listen_status(const char *widget_id, widget_instance_event_cb cb, void *data)
 {
@@ -1146,7 +1170,8 @@ EAPI int widget_instance_listen_status(const char *widget_id, widget_instance_ev
        cb_info->cb = cb;
        cb_info->data = data;
        if (!lifecycle_tbl) {
-               lifecycle_tbl = g_hash_table_new(g_str_hash, g_str_equal);
+               lifecycle_tbl = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+                               __destroy_lifecycle_local);
                if (!lifecycle_tbl) {
                        free(cb_info);
                        return -1;
@@ -1172,8 +1197,6 @@ EAPI int widget_instance_unlisten_status(const char *widget_id)
                return -1;
 
        g_hash_table_remove(lifecycle_tbl, widget_id);
-       free(cb_info->widget_id);
-       free(cb_info);
 
        return 0;
 }
index 2b3600f..170a752 100644 (file)
@@ -303,8 +303,10 @@ static int _resolution_update_from_file(void)
        dic = iniparser_load(file_path);
        if (dic == NULL) {
                _E("fail to load [%s] ", file_path);
+               free(file_path);
                return WIDGET_ERROR_IO_ERROR;
        }
+       free(file_path);
        snprintf(key_format, sizeof(key_format), "%s:%s",
                        RESOLUTION_SECTION_NAME, RESOLUTION_FORMAT);
        key_num = iniparser_getsecnkeys(dic, RESOLUTION_SECTION_NAME);
@@ -484,6 +486,8 @@ static int _get_widget_supported_sizes(const char *widget_id, uid_t uid,
                _E("failed to convert size");
                free(width);
                free(height);
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
                return WIDGET_ERROR_FAULT;
        }
        *w = width;
@@ -629,6 +633,8 @@ static int _get_widget_list(const char *pkgid, uid_t uid, GList **list)
                if (item == NULL) {
                        /* LCOV_EXCL_START */
                        _E("out of memory");
+                       sqlite3_finalize(stmt);
+                       sqlite3_close_v2(db);
                        return WIDGET_ERROR_OUT_OF_MEMORY;
                        /* LCOV_EXCL_STOP */
                }
@@ -1760,6 +1766,7 @@ EAPI int widget_service_get_content_of_widget_instance(const char *widget_id, co
        ret = aul_widget_instance_get_content(widget_id, widget_instance_id, &raw);
        if (raw) {
                *b = bundle_decode((const bundle_raw *)raw, strlen(raw));
+               free(raw);
                return WIDGET_ERROR_NONE;
        }