From: Eunhye Choi Date: Wed, 11 Sep 2024 08:13:19 +0000 (+0900) Subject: [UTC/CTC][player][NonACR][Fix ASAN bug] X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d7e03b4594d8a64210bc44dcc199f7a9b84e496c;p=test%2Ftct%2Fnative%2Fapi.git [UTC/CTC][player][NonACR][Fix ASAN bug] - Resolve double-free and heap-use-after-free bug - Replace deprecated API of media packet to new API Change-Id: Ib6b7c14eb1ceae58c0b3fb68f63d0b738a35fc43 --- diff --git a/src/ctc/player/CTs-player-common.c b/src/ctc/player/CTs-player-common.c index a49a00c4f..99bffd3a9 100755 --- a/src/ctc/player/CTs-player-common.c +++ b/src/ctc/player/CTs-player-common.c @@ -76,7 +76,7 @@ char* PlayerGetState(player_state_e eState) * @description Creates a player handler, sets an uri and prepares the handler * @parameter [IN] bool bPrepare [if it is true, player would be prepared. Otherwise, player would not be prepared] * [IN] int eMediaType [if it is 0, player_set_uri would be set with an audio file. Otherwise, player_set_uri would be set with a video file] -* @return true if successful, otherwise false. +* @return true if successful, otherwise false. */ bool PlayerInitialization(bool bPrepare, MediaTypeEnumeration eMediaType) { @@ -88,13 +88,13 @@ bool PlayerInitialization(bool bPrepare, MediaTypeEnumeration eMediaType) { FPRINTF("[Line : %d][%s] player_create failed, error returned = %s\\n", __LINE__, API_NAMESPACE, PlayerGetError(nRet)); return false; - } + } if ( g_PlayerHandler == NULL ) { FPRINTF("[Line : %d][%s] player handler is NULL\\n", __LINE__, API_NAMESPACE); return false; - } + } nRet = player_get_state(g_PlayerHandler, &eState); if ( nRet != PLAYER_ERROR_NONE ) @@ -115,7 +115,7 @@ bool PlayerInitialization(bool bPrepare, MediaTypeEnumeration eMediaType) if ( eMediaType == MeidaType_Audio ) { char *pszAudioPath = MediaPlayerGetDataPath(MEDIA_AUDIO); - + nRet = player_set_uri(g_PlayerHandler, pszAudioPath); #if defined(WEARABLE) bool bValue = false; @@ -147,7 +147,7 @@ bool PlayerInitialization(bool bPrepare, MediaTypeEnumeration eMediaType) FPRINTF("[Line : %d][%s] player_prepare failed, error returned = %s\\n", __LINE__, API_NAMESPACE, PlayerGetError(nRet)); PlayerDestroy(false); return false; - } + } nRet = player_get_state(g_PlayerHandler, &eState); if ( nRet != PLAYER_ERROR_NONE ) @@ -156,7 +156,7 @@ bool PlayerInitialization(bool bPrepare, MediaTypeEnumeration eMediaType) PlayerDestroy(false); return false; } - + FPRINTF("[Line : %d][%s] player_get_state returned = %s\\n", __LINE__, API_NAMESPACE, PlayerGetState(eState)); if ( eState != PLAYER_STATE_READY ) { @@ -165,36 +165,38 @@ bool PlayerInitialization(bool bPrepare, MediaTypeEnumeration eMediaType) return false; } } + return true; } /** * @function PlayerDestroy * @description Unprepare and destroy the player handler * @parameter [IN] bIsUnprepare, whether unprepare needed or not -* @return true if successful, else false +* @return true if successful, else false */ bool PlayerDestroy(bool bIsUnprepare) { + bool ret = true; int nRet = PLAYER_ERROR_NONE; if ( bIsUnprepare ) { - nRet = player_unprepare(g_PlayerHandler); + nRet = player_unprepare(g_PlayerHandler); if ( nRet != PLAYER_ERROR_NONE ) { FPRINTF("[Line : %d][%s] player_unprepare failed, error returned = %s\\n", __LINE__, API_NAMESPACE, PlayerGetError(nRet)); - return false; + ret = false; } } nRet = player_destroy(g_PlayerHandler); if ( nRet != PLAYER_ERROR_NONE ) { FPRINTF("[Line : %d][%s] player_destroy failed, error returned = %s\\n", __LINE__, API_NAMESPACE, PlayerGetError(nRet)); - return false; + ret = false; } g_PlayerHandler = NULL; - return true; + return ret; } /** @@ -204,7 +206,7 @@ bool PlayerDestroy(bool bIsUnprepare) * [OUT] pfPreserveRightVol, save the right vol * [IN] fSetLeftVol, set the current left vol * [IN] fSetRightVol, set the current right vol -* @return true if successful, else false +* @return true if successful, else false */ bool PlayerSetVolume(float *pfPreserveLeftVol, float *pfPreserveRightVol, float fSetLeftVol, float fSetRightVol) { @@ -230,7 +232,7 @@ bool PlayerSetVolume(float *pfPreserveLeftVol, float *pfPreserveRightVol, float return true; } -/** +/** * @function PlayerGmainLoopCallBack * @description Callback for GmainLoop and player start during callback time. * @parameter [IN] data, user data @@ -246,7 +248,7 @@ gboolean PlayerGmainLoopCallBack(gpointer data) { nRet = player_start(g_PlayerHandler); if ( nRet != PLAYER_ERROR_NONE ) - { + { FPRINTF("[Line : %d][%s] player_start failed, error returned = %s\\n", __LINE__, API_NAMESPACE, PlayerGetError(nRet)); PlayerDestroy(true); } @@ -267,7 +269,7 @@ gboolean PlayerGmainLoopCallBack(gpointer data) { nRet = player_stop(g_PlayerHandler); if ( nRet != PLAYER_ERROR_NONE ) - { + { FPRINTF("[Line : %d][%s] player_stop failed, error returned = %s\\n", __LINE__, API_NAMESPACE, PlayerGetError(nRet)); PlayerDestroy(true); } @@ -300,7 +302,7 @@ void RuntimeErrorInfo(char *pszApiName, int nResult) case RUNTIME_INFO_ERROR_INVALID_PARAMETER: pszErrInfo = "RUNTIME_INFO_ERROR_INVALID_PARAMETER"; break; case RUNTIME_INFO_ERROR_OUT_OF_MEMORY: pszErrInfo = "RUNTIME_INFO_ERROR_OUT_OF_MEMORY"; break; case RUNTIME_INFO_ERROR_IO_ERROR: pszErrInfo = "RUNTIME_INFO_ERROR_IO_ERROR"; break; - case RUNTIME_INFO_ERROR_PERMISSION_DENIED: pszErrInfo = "RUNTIME_INFO_ERROR_PERMISSION_DENIED"; break; + case RUNTIME_INFO_ERROR_PERMISSION_DENIED: pszErrInfo = "RUNTIME_INFO_ERROR_PERMISSION_DENIED"; break; } FPRINTF("[Line : %d][%s] %s is failed, error returned = %s\\n", __LINE__, API_NAMESPACE, pszApiName, pszErrInfo); @@ -320,11 +322,11 @@ char* MediaPlayerGetDataPath(char *pszFileName) FPRINTF("[Line : %d][%s] app_get_resource_path() returned invalid path\\n", __LINE__, API_NAMESPACE); return pszImgPath; } - + pszImgPath = (char*) calloc(1, strlen(pszAppData) + strlen(pszFileName)+1); if (pszImgPath == NULL) return pszImgPath; - + snprintf(pszImgPath, strlen(pszAppData) + strlen(pszFileName)+2, "%s%s",pszAppData, pszFileName); FPRINTF("[Line : %d][%s] app_get_resource_path() is %s\\n", __LINE__, API_NAMESPACE,pszImgPath); return pszImgPath; diff --git a/src/utc/player/utc-media-player-es.c b/src/utc/player/utc-media-player-es.c index 76bbc0889..86034b52a 100644 --- a/src/utc/player/utc-media-player-es.c +++ b/src/utc/player/utc-media-player-es.c @@ -239,8 +239,8 @@ static void feed_video_data() int read = 0; void *buf_data_ptr = NULL; - if (media_packet_create_alloc(video_fmt, NULL, NULL, &video_pkt) != MEDIA_PACKET_ERROR_NONE) { - PRINT_UTC_LOG("[Line : %d][%s] fail to alloc media_packet\\n", __LINE__, API_NAMESPACE); + if (media_packet_new_alloc(video_fmt, NULL, NULL, &video_pkt) != MEDIA_PACKET_ERROR_NONE) { + PRINT_UTC_LOG("[Line : %d][%s] fail to alloc media_packet\\n", __LINE__, API_NAMESPACE); return; } @@ -271,13 +271,10 @@ static void feed_video_data() g_ret = player_push_media_stream(player, video_pkt); pts += ES_DEFAULT_VIDEO_PTS_OFFSET; - goto FREE_PACKET; - FREE_PACKET: /* destroy media packet after use */ - media_packet_destroy(video_pkt); + media_packet_unref(video_pkt); video_pkt = NULL; - return; } static void feed_video_data_thread_func() @@ -329,7 +326,7 @@ static void feed_audio_data() int read = 0; void *buf_data_ptr = NULL; - if (media_packet_create_alloc(audio_fmt, NULL, NULL, &audio_pkt) != MEDIA_PACKET_ERROR_NONE) { + if (media_packet_new_alloc(audio_fmt, NULL, NULL, &audio_pkt) != MEDIA_PACKET_ERROR_NONE) { PRINT_UTC_LOG("[Line : %d][%s] fail to alloc media_packet\\n", __LINE__, API_NAMESPACE); return; } @@ -359,13 +356,10 @@ static void feed_audio_data() g_ret = player_push_media_stream(player, audio_pkt); pts += ES_DEFAULT_AUDIO_PTS_OFFSET; - goto FREE_PACKET; - FREE_PACKET: /* destroy media packet after use */ - media_packet_destroy(audio_pkt); - video_pkt = NULL; - return; + media_packet_unref(audio_pkt); + audio_pkt = NULL; } static void feed_audio_data_thread_func() @@ -482,19 +476,19 @@ void utc_media_player_es_cleanup(void) if (video_fmt) media_format_unref(video_fmt); + video_fmt = NULL; if (audio_fmt) media_format_unref(audio_fmt); + audio_fmt = NULL; - if (file_src) { + if (file_src) fclose(file_src); - file_src = NULL; - } + file_src = NULL; - if (audio_file_src) { + if (audio_file_src) fclose(audio_file_src); - audio_file_src = NULL; - } + audio_file_src = NULL; if (player){ ret = player_get_state (player, &state); @@ -509,9 +503,11 @@ void utc_media_player_es_cleanup(void) } if (media_path) free(media_path); + media_path = NULL; if (audio_media_path) free(audio_media_path); + audio_media_path = NULL; #ifndef TIZENIOT destroy_window();