From a09c6b955e4c982422d3e767f38f3b9329d906d5 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 24 Apr 2017 14:42:08 -0400 Subject: [PATCH] utils.muxer: fix unhandled connected ports during notif. iter. init. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- plugins/utils/muxer/muxer.c | 41 ++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index e790ab01..033a0abb 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -50,6 +50,7 @@ struct muxer_comp { unsigned int next_port_num; size_t available_input_ports; bool error; + bool initializing_muxer_notif_iter; }; struct muxer_upstream_notif_iter { @@ -514,7 +515,7 @@ int get_notif_ts_ns(struct muxer_comp *muxer_comp, case BT_NOTIFICATION_TYPE_INACTIVITY: cc_prio_map = - bt_notification_event_get_clock_class_priority_map( + bt_notification_inactivity_get_clock_class_priority_map( notif); break; default: @@ -867,14 +868,19 @@ enum bt_notification_iterator_status muxer_notif_iter_init( assert(priv_comp); muxer_comp = bt_private_component_get_user_data(priv_comp); assert(muxer_comp); - muxer_notif_iter = g_new0(struct muxer_notif_iter, 1); - if (!muxer_notif_iter) { + + if (muxer_comp->initializing_muxer_notif_iter) { + /* + * Weird, unhandled situation: downstream creates a + * muxer notification iterator while creating another + * muxer notification iterator (same component). + */ goto error; } - ret = muxer_notif_iter_init_newly_connected_ports(muxer_comp, - muxer_notif_iter); - if (ret) { + muxer_comp->initializing_muxer_notif_iter = true; + muxer_notif_iter = g_new0(struct muxer_notif_iter, 1); + if (!muxer_notif_iter) { goto error; } @@ -886,6 +892,21 @@ enum bt_notification_iterator_status muxer_notif_iter_init( goto error; } + /* + * Add the muxer notification iterator to the component's array + * of muxer notification iterators here because + * muxer_notif_iter_init_newly_connected_ports() can cause + * muxer_port_connected() to be called, which adds the newly + * connected port to each muxer notification iterator's list of + * newly connected ports. + */ + g_ptr_array_add(muxer_comp->muxer_notif_iters, muxer_notif_iter); + ret = muxer_notif_iter_init_newly_connected_ports(muxer_comp, + muxer_notif_iter); + if (ret) { + goto error; + } + /* Set the initial "next" return value */ ret = muxer_notif_iter_set_next_next_return(muxer_comp, muxer_notif_iter); @@ -896,10 +917,15 @@ enum bt_notification_iterator_status muxer_notif_iter_init( ret = bt_private_notification_iterator_set_user_data(priv_notif_iter, muxer_notif_iter); assert(ret == 0); - g_ptr_array_add(muxer_comp->muxer_notif_iters, muxer_notif_iter); goto end; error: + if (g_ptr_array_index(muxer_comp->muxer_notif_iters, + muxer_comp->muxer_notif_iters->len - 1) == muxer_notif_iter) { + g_ptr_array_remove_index(muxer_comp->muxer_notif_iters, + muxer_comp->muxer_notif_iters->len - 1); + } + destroy_muxer_notif_iter(muxer_notif_iter); ret = bt_private_notification_iterator_set_user_data(priv_notif_iter, NULL); @@ -907,6 +933,7 @@ error: status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; end: + muxer_comp->initializing_muxer_notif_iter = false; bt_put(priv_comp); return status; } -- 2.34.1