Fix memory leak (sound-server) : valgrind 69/112569/2
authorSeungbae Shin <seungbae.shin@samsung.com>
Wed, 1 Feb 2017 12:36:02 +0000 (21:36 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 2 Feb 2017 06:21:41 +0000 (15:21 +0900)
[Version] 0.10.85
[Profile] Common
[Issue Type] Memory Leak

Change-Id: I0dd98fd197947fd3f482260c787455da50efb585

mm_sound_client.c
mm_sound_pa_client.c
packaging/libmm-sound.spec
server/mm_sound_mgr_ipc_dbus.c

index 2744fef..6c46fe2 100644 (file)
@@ -1294,6 +1294,11 @@ static void _focus_open_callback(int index, bool is_for_watching)
 
        debug_fenter();
 
+       if (index < 0 || index >= FOCUS_HANDLE_MAX) {
+               debug_error("Invalid focus handle index [%d]", index);
+               return;
+       }
+
        if (is_for_watching) {
                filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
        } else {
@@ -1339,6 +1344,11 @@ void _focus_close_callback(int index, bool is_for_watching)
 
        debug_fenter();
 
+       if (index < 0 || index >= FOCUS_HANDLE_MAX) {
+               debug_error("Invalid focus handle index [%d]", index);
+               return;
+       }
+
        if (g_focus_sound_handle[index].focus_fd < 0) {
                debug_error("Close fail : index(%d)", index);
        } else {
@@ -1450,12 +1460,13 @@ static bool _focus_remove_sound_callback(int index)
 
        debug_fenter();
 
-       h = &g_focus_sound_handle[index];
-       if (h == NULL) {
-               debug_error("g_focus_sound_handle[%d] is NULL", index);
+       if (index < 0 || index >= FOCUS_HANDLE_MAX) {
+               debug_error("Invalid focus handle index [%d]", index);
                return false;
        }
 
+       h = &g_focus_sound_handle[index];
+
        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);
@@ -1495,6 +1506,12 @@ static bool _focus_remove_sound_callback(int index)
 static void _focus_add_callback(int index, bool is_for_watching)
 {
        debug_fenter();
+
+       if (index < 0 || index >= FOCUS_HANDLE_MAX) {
+               debug_error("Invalid focus handle index [%d]", index);
+               return;
+       }
+
        if (!is_for_watching) {
                if (!_focus_add_sound_callback(index, g_focus_sound_handle[index].focus_fd,
                                                                        (gushort)POLLIN | POLLPRI, _focus_callback_handler))
index 3cf52c5..9653075 100644 (file)
@@ -417,6 +417,9 @@ int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_i
         handle->handle, handle->mode, handle->policy, handle->volume_type, handle->gain_type,
         handle->rate, handle->channels, ss->format, handle->stream_idx, handle->s, handle->source_type, handle_inout);
 
+    if (proplist)
+        pa_proplist_free(proplist);
+
     return handle->handle;
 
 fail:
index 01c84e1..9023b45 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.10.84
+Version:    0.10.85
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 1fc3ec1..b580b28 100644 (file)
@@ -298,7 +298,7 @@ send_reply:
 static void handle_method_play_file_start(GDBusMethodInvocation* invocation)
 {
        gchar* filename = NULL;
-       char *stream_type = NULL;
+       gchar *stream_type = NULL;
        gint32 ret = MM_ERROR_NONE, slotid = 0;
        gint32 tone = 0, repeat = 0, volume = 0, vol_config = 0, priority = 0;
        gint32 session_type = 0, session_option = 0, pid = 0, handle_route =0, stream_index = 0;
@@ -323,6 +323,7 @@ static void handle_method_play_file_start(GDBusMethodInvocation* invocation)
        ret = _MMSoundMgrIpcPlayFile(filename, tone, repeat, volume, vol_config, priority,
                                session_type, session_option, _get_sender_pid(invocation), handle_route, enable_session, &slotid, stream_type, stream_index);
 
+
 send_reply:
        if (ret == MM_ERROR_NONE) {
                _method_call_return_value(invocation, g_variant_new("(i)", slotid));
@@ -330,13 +331,16 @@ send_reply:
                _method_call_return_error(invocation, ret);
        }
 
+       g_free(filename);
+       g_free(stream_type);
+
        debug_fleave();
 }
 
 static void handle_method_play_file_start_with_stream_info(GDBusMethodInvocation* invocation)
 {
        gchar* filename = NULL;
-       char *stream_type = NULL;
+       gchar *stream_type = NULL;
        gint32 ret = MM_ERROR_NONE, slotid = 0;
        gint32 repeat = 0, volume = 0, priority = 0, pid = 0, handle_route =0, stream_index = 0;
        GVariant *params = NULL;
@@ -366,6 +370,9 @@ send_reply:
                _method_call_return_error(invocation, ret);
        }
 
+       g_free(filename);
+       g_free(stream_type);
+
        debug_fleave();
 }
 
@@ -373,7 +380,7 @@ static void handle_method_play_dtmf(GDBusMethodInvocation* invocation)
 {
        int ret = MM_ERROR_NONE, slotid = 0;
        int tone = 0, repeat = 0, volume = 0, vol_config = 0, session_type = 0, session_option = 0, pid = 0, stream_index = 0;
-       char* stream_type = NULL;
+       gchar* stream_type = NULL;
        gboolean enable_session = 0;
        GVariant *params = NULL;
 
@@ -398,6 +405,7 @@ send_reply:
                _method_call_return_error(invocation, ret);
        }
 
+       g_free(stream_type);
 
        debug_fleave();
 }