Fix memory leak : valgrind 86/112386/7 accepted/tizen/3.0/common/20170202.151059 accepted/tizen/3.0/ivi/20170202.085717 accepted/tizen/3.0/mobile/20170202.085634 accepted/tizen/3.0/tv/20170202.085646 accepted/tizen/3.0/wearable/20170202.085700 submit/tizen_3.0/20170201.113021
authorSeungbae Shin <seungbae.shin@samsung.com>
Tue, 31 Jan 2017 14:10:48 +0000 (23:10 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Wed, 1 Feb 2017 10:33:03 +0000 (19:33 +0900)
[Version] 0.10.85
[Profile] Common
[Issue Type] Memory Leak

Change-Id: I1d5878e0517741ea1b5176dd634010c9680ac820

common/mm_sound_dbus.c
focus_server/mm_sound_mgr_focus.c
mm_sound_client.c

index e33cc82..600d583 100644 (file)
@@ -315,8 +315,8 @@ static int _dbus_subscribe_signal(GDBusConnection *conn, const char* object_name
 
        debug_log("Dbus subscirbe signal with Obj'%s' Intf'%s' sig'%s'", object_name, intf_name, signal_name);
 
-       subs_id = g_dbus_connection_signal_subscribe(conn, NULL, intf_name, signal_name, object_name, \
-                        NULL , G_DBUS_SIGNAL_FLAGS_NONE , signal_cb, userdata, NULL );
+       subs_id = g_dbus_connection_signal_subscribe(conn, NULL, intf_name, signal_name, object_name,
+                                                                                               NULL, G_DBUS_SIGNAL_FLAGS_NONE , signal_cb, userdata, freefunc);
 
        if (!subs_id) {
                debug_error ("g_dbus_connection_signal_subscribe() failed ");
index 54b9a06..05bd28c 100644 (file)
@@ -281,14 +281,12 @@ static int _mm_sound_mgr_focus_do_watch_callback(focus_type_e focus_type, focus_
                                 *
                                 **************************************/
 RELEASE:
-                               if (filename) {
-                                       g_free (filename);
-                                       filename = NULL;
-                               }
-                               if (filename2) {
-                                       g_free (filename2);
-                                       filename2 = NULL;
-                               }
+                               g_free(filename);
+                               filename = NULL;
+
+                               g_free(filename2);
+                               filename2 = NULL;
+
                                if (fd_FOCUS != -1) {
                                        close(fd_FOCUS);
                                        fd_FOCUS = -1;
@@ -523,14 +521,12 @@ int _mm_sound_mgr_focus_do_callback(focus_command_e command, focus_node_t *victi
                _mm_sound_mgr_focus_do_watch_callback((focus_type_e)assaulter_param->request_type, command, victim_node, assaulter_param);
 
 RELEASE:
-       if (filename) {
-               g_free (filename);
-               filename = NULL;
-       }
-       if (filename2) {
-               g_free (filename2);
-               filename2 = NULL;
-       }
+       g_free(filename);
+       filename = NULL;
+
+       g_free(filename2);
+       filename2 = NULL;
+
        if (fd_FOCUS != -1) {
                close(fd_FOCUS);
                fd_FOCUS = -1;
index 87a6bf8..2744fef 100644 (file)
@@ -409,8 +409,7 @@ static void play_end_callback_data_free_func(void *data)
        struct callback_data *cb_data = (struct callback_data*) data;
 
        if (cb_data) {
-               if (cb_data->extra_data)
-                       g_free(cb_data->extra_data);
+               g_free(cb_data->extra_data);
                g_free(cb_data);
        }
 }
@@ -1436,63 +1435,59 @@ static bool _focus_add_sound_callback(int index, int fd, gushort events, focus_g
        return true;
 
 ERROR:
-       if (g_src_funcs)
-               g_free(g_src_funcs);
-       if (g_poll_fd)
-               g_free(g_poll_fd);
+       g_free(g_src_funcs);
+       g_free(g_poll_fd);
        if (g_src)
                g_source_unref(g_src);
 
        return false;
 }
 
-static bool _focus_remove_sound_callback(int index, gushort events)
+static bool _focus_remove_sound_callback(int index)
 {
        bool ret = true;
+       focus_sound_info_t *h = NULL;
 
        debug_fenter();
 
-       g_mutex_clear(&g_focus_sound_handle[index].focus_lock);
+       h = &g_focus_sound_handle[index];
+       if (h == NULL) {
+               debug_error("g_focus_sound_handle[%d] is NULL", index);
+               return false;
+       }
 
-       GSourceFuncs *g_src_funcs = g_focus_sound_handle[index].g_src_funcs;
-       GPollFD *g_poll_fd = g_focus_sound_handle[index].g_poll_fd;     /* store file descriptor */
-       if (!g_poll_fd) {
-               debug_error("g_poll_fd is null..");
+       if (h->focus_src && h->g_poll_fd) {
+               debug_log("g_source_remove_poll : fd(%d), event(0x%x)",
+                               h->g_poll_fd->fd, h->g_poll_fd->events);
+               g_source_remove_poll(h->focus_src, h->g_poll_fd);
+       } else {
+               debug_error("[%d] focus_src[%p], g_poll_fd[%p]",
+                                       index, h->focus_src, h->g_poll_fd);
                ret = false;
-               goto RELEASE;
        }
-       g_poll_fd->fd = g_focus_sound_handle[index].focus_fd;
-       g_poll_fd->events = events;
 
-       if (!g_focus_sound_handle[index].focus_src) {
-               debug_error("g_focus_sound_handle[%d].focus_src is null..", index);
-               ret = false;
-               goto RELEASE;
+       if (h->focus_src) {
+               g_source_destroy(h->focus_src);
+               g_source_unref(h->focus_src);
+               h->focus_src = NULL;
        }
-       g_source_remove_poll(g_focus_sound_handle[index].focus_src, g_poll_fd);
-       debug_log("g_source_remove_poll : fd(%d), event(%x)", g_poll_fd->fd, g_poll_fd->events);
 
-RELEASE:
-       if (g_focus_sound_handle[index].focus_src)
-               g_source_destroy(g_focus_sound_handle[index].focus_src);
+       debug_log("g_free : g_src_funcs(%p), g_poll_fd(%p)",
+                       h->g_src_funcs, h->g_poll_fd);
 
-       debug_log("g_free : g_src_funcs(%x), g_poll_fd(%x)", g_src_funcs, g_poll_fd);
-       if (g_src_funcs) {
-               g_free(g_src_funcs);
-               g_src_funcs = NULL;
-       }
-       if (g_poll_fd) {
-               g_free(g_poll_fd);
-               g_poll_fd = NULL;
-       }
+       g_free(h->g_src_funcs);
+       h->g_src_funcs = NULL;
 
-       g_focus_sound_handle[index].g_src_funcs = NULL;
-       g_focus_sound_handle[index].g_poll_fd = NULL;
-       g_focus_sound_handle[index].focus_src = NULL;
-       g_focus_sound_handle[index].focus_callback = NULL;
-       g_focus_sound_handle[index].watch_callback = NULL;
+       g_free(h->g_poll_fd);
+       h->g_poll_fd = NULL;
+
+       h->focus_callback = NULL;
+       h->watch_callback = NULL;
+
+       g_mutex_clear(&h->focus_lock);
 
        debug_fleave();
+
        return ret;
 }
 
@@ -1501,15 +1496,13 @@ static void _focus_add_callback(int index, bool is_for_watching)
 {
        debug_fenter();
        if (!is_for_watching) {
-               if (!_focus_add_sound_callback(index, g_focus_sound_handle[index].focus_fd, (gushort)POLLIN | POLLPRI, _focus_callback_handler)) {
-                       debug_error("failed to _focus_add_sound_callback()");
-                       //return false;
-               }
+               if (!_focus_add_sound_callback(index, g_focus_sound_handle[index].focus_fd,
+                                                                       (gushort)POLLIN | POLLPRI, _focus_callback_handler))
+                       debug_error("failed to _focus_add_sound_callback(%p)", _focus_callback_handler);
        } else { // need to check if it's necessary
-               if (!_focus_add_sound_callback(index, g_focus_sound_handle[index].focus_fd, (gushort)POLLIN | POLLPRI, _focus_watch_callback_handler)) {
-                       debug_error("failed to _focus_add_sound_callback()");
-                       //return false;
-               }
+               if (!_focus_add_sound_callback(index, g_focus_sound_handle[index].focus_fd,
+                                                                       (gushort)POLLIN | POLLPRI, _focus_watch_callback_handler))
+                       debug_error("failed to _focus_add_sound_callback(%p)", _focus_watch_callback_handler);
        }
        debug_fleave();
 }
@@ -1517,10 +1510,8 @@ static void _focus_add_callback(int index, bool is_for_watching)
 static void _focus_remove_callback(int index)
 {
        debug_fenter();
-       if (!_focus_remove_sound_callback(index, (gushort)POLLIN | POLLPRI)) {
+       if (!_focus_remove_sound_callback(index))
                debug_error("failed to __focus_remove_sound_callback()");
-               //return false;
-       }
        debug_fleave();
 }