From 791b2e7b67027a1860d9289ce441619db671c3b3 Mon Sep 17 00:00:00 2001 From: Gilbok Lee Date: Fri, 11 Sep 2020 14:50:12 +0900 Subject: [PATCH] [0.3.134] Check Gsource flags before remove callback data - Fix crash when streaming case Change-Id: I98e4e78ba13077de59f8e01ada67048632ea015a --- packaging/capi-media-player.spec | 2 +- src/player.c | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packaging/capi-media-player.spec b/packaging/capi-media-player.spec index 7ef095e..1fb0ef0 100644 --- a/packaging/capi-media-player.spec +++ b/packaging/capi-media-player.spec @@ -1,6 +1,6 @@ Name: capi-media-player Summary: A Media Player API -Version: 0.3.133 +Version: 0.3.134 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/player.c b/src/player.c index 8a65db3..22b493d 100644 --- a/src/player.c +++ b/src/player.c @@ -1327,7 +1327,7 @@ gboolean _player_event_job_function(void *user_data) ev = data->int_data; if ((ev != MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME) && (ev != MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME)) - LOGD("enter ev:%d", ev); + LOGD("enter ev:%d(%p)", ev, data); g_mutex_lock(&data->event_mutex); @@ -1355,10 +1355,11 @@ DONE: /* unlock and release event */ g_mutex_unlock(&data->event_mutex); g_mutex_clear(&data->event_mutex); - if (data->recv_data) { g_free(data->recv_data->buffer); + data->recv_data->buffer = NULL; g_free(data->recv_data); + data->recv_data = NULL; } g_free(data); @@ -1515,27 +1516,37 @@ static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_e gboolean ret = FALSE; if (remove_all || (event_data->int_data == event_type)) { + GSource *source = NULL; + gboolean check_in_call = FALSE; LOGD("remove idle event [%p:%d]", event_data, event_data->int_data); - + source = g_main_context_find_source_by_user_data ( + g_main_context_default (), event_data); ret = g_idle_remove_by_data(event_data); - if (ret == FALSE) { + if (source) + check_in_call = source->flags & G_HOOK_FLAG_IN_CALL; + + if (!ret || check_in_call) { /* will be handled at _player_event_job_function() as an exception */ event_data->cb_info = NULL; LOGW("failed to remove, idle callback will be called later"); } /* set cb to null */ - set_null_user_cb(cb_info, event_data->int_data); + if (remove_all) + set_null_user_cb(cb_info, event_data->int_data); + ev->idle_ev_list = g_list_remove(ev->idle_ev_list, (gpointer)event_data); g_mutex_unlock(&event_data->event_mutex); - if (ret == TRUE) { + if (ret && !check_in_call) { g_mutex_clear(&event_data->event_mutex); if (event_data->recv_data) { g_free(event_data->recv_data->buffer); + event_data->recv_data->buffer = NULL; g_free(event_data->recv_data); + event_data->recv_data = NULL; } g_free(event_data); event_data = NULL; -- 2.7.4