fix mem leak 30/144930/1
authorEunhae Choi <eunhae1.choi@samsung.com>
Fri, 18 Aug 2017 10:48:28 +0000 (19:48 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Fri, 18 Aug 2017 10:48:28 +0000 (19:48 +0900)
Change-Id: Ibe3a294bfa0129d180ee47ceb6281e7712ed844f

legacy/src/legacy_player.c
muse/src/muse_player.c

index d5ee451916d41acae091bc1a420b07d284c6d8b2..7300d6a9e5ab31a02381173a93713e62a9060e0b 100644 (file)
@@ -579,7 +579,10 @@ static int __msg_callback(int message, void *param, void *user_data)
                if (PLAYER_ERROR_NOT_SUPPORTED_FILE == err_code && handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
                        LOGW("failed to pause, so prepare cb will be released soon");
                        handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
-                       handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
+                       if (handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
+                               g_free(handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]);
+                               handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
+                       }
                }
                break;
        case MM_MESSAGE_STATE_CHANGED:  /* 0x03 */
@@ -1099,9 +1102,18 @@ int legacy_player_destroy(player_h player)
        player_s *handle = (player_s *)player;
 
        __ADD_MESSAGE(handle, PLAYER_MESSAGE_LOOP_EXIT);
+
        __RELEASEIF_PREPARE_THREAD(handle->prepare_async_thread);
        __RELEASEIF_MESSAGE_THREAD(handle->message_thread);
 
+       if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
+               handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
+               if (handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
+                       g_free(handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]);
+                       handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
+               }
+       }
+
        int ret = mm_player_destroy(handle->mm_handle);
 
        if (handle->pkt_fmt) {
@@ -1197,8 +1209,7 @@ int legacy_player_prepare_async(player_h player, player_prepared_cb callback, vo
                        LOGW("[%s] Failed to set display surface type 'MM_DISPLAY_SURFACE_NULL' (0x%x)", __FUNCTION__, ret);
        } else {
                ret = mm_player_get_attribute(handle->mm_handle, NULL, "display_visible", &visible, (char *)NULL);
-               if (ret != MM_ERROR_NONE)
-                       return __player_convert_error_code(ret, (char *)__FUNCTION__);
+               if (ret != MM_ERROR_NONE) goto ERROR;
 
                if (!visible)
                        value = FALSE;
@@ -1206,19 +1217,13 @@ int legacy_player_prepare_async(player_h player, player_prepared_cb callback, vo
                        value = TRUE;
 
                ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_visible", value, (char *)NULL);
-               if (ret != MM_ERROR_NONE)
-                       return __player_convert_error_code(ret, (char *)__FUNCTION__);
+               if (ret != MM_ERROR_NONE) goto ERROR;
        }
 
        ret = mm_player_realize(handle->mm_handle);
        if (ret != MM_ERROR_NONE) {
                LOGE("[%s] Failed to realize - 0x%x", __FUNCTION__, ret);
-               LOGW("prepare cb will be released soon");
-               if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
-                       handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
-                       handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
-               }
-               return __player_convert_error_code(ret, (char *)__FUNCTION__);
+               goto ERROR;
        }
 
        if (!handle->is_progressive_download) {
@@ -1226,12 +1231,28 @@ int legacy_player_prepare_async(player_h player, player_prepared_cb callback, vo
 
                if (ret != 0) {
                        LOGE("[%s] failed to create thread ret = %d", __FUNCTION__, ret);
+                       if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
+                               handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
+                               /* user_data will be free at player_disp_prepare_async() */
+                               handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
+                       }
                        return PLAYER_ERROR_OUT_OF_MEMORY;
                }
        }
 
        LOGI("[%s] End", __FUNCTION__);
        return PLAYER_ERROR_NONE;
+
+ERROR:
+       LOGW("prepare cb is released");
+       if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
+               handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
+               /* user_data will be free at player_disp_prepare_async() */
+               handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
+       }
+
+       LOGE("LEAVE mm_err:0x%X", ret);
+       return __player_convert_error_code(ret, (char *)__FUNCTION__);
 }
 
 int legacy_player_prepare(player_h player)
@@ -1309,16 +1330,20 @@ int legacy_player_unprepare(player_h player)
                handle->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
        }
 
-       if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
-               handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
-               handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
-       }
-
        if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
                LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
                return PLAYER_ERROR_INVALID_STATE;
        }
 
+       if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
+               LOGW("Need to check. prepare cb have to be reset before");
+               handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
+               if (handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
+                       g_free(handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]);
+                       handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
+               }
+       }
+
        __RELEASEIF_PREPARE_THREAD(handle->prepare_async_thread);
 
        int ret = mm_player_unrealize(handle->mm_handle);
index 5ea1413943d03da8f8550bfdeaee8c1b7ec16448..1d9ff69ca1f6408a5b2365f9b7e919b0b7c0a595 100644 (file)
@@ -1171,6 +1171,9 @@ int player_disp_prepare_async(muse_module_h module)
        } /* else is error */
 
 ERROR:
+       if (prepare_data)
+               g_free(prepare_data);
+
        player_msg_return(api, ret, module);
        return ret;
 }