Skip to content

Commit f2922c2

Browse files
authored
Fixed conference destruction and failure handling (#4497)
1 parent e076887 commit f2922c2

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed

pjmedia/src/pjmedia/conf_thread.c

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -616,20 +616,20 @@ static pj_status_t create_conf_port( pj_pool_t *parent_pool,
616616
#else
617617
pool = pj_pool_create(parent_pool->factory, pname, 500, 500, NULL);
618618
#endif
619-
if (!pool) {
620-
status = PJ_ENOMEM;
621-
goto on_return;
622-
}
619+
if (!pool)
620+
return PJ_ENOMEM;
623621

624622
/* Create port. */
625623
conf_port = PJ_POOL_ZALLOC_T(pool, struct conf_port);
626-
PJ_ASSERT_ON_FAIL(conf_port, {status = PJ_ENOMEM; goto on_return;});
624+
PJ_ASSERT_ON_FAIL(conf_port, {pj_pool_release(pool); return PJ_ENOMEM;});
627625
conf_port->pool = pool;
628626

629627
/* Increment port ref count to avoid premature destroy due to
630628
* asynchronous port removal.
631629
*/
632630
if (port) {
631+
conf_port->port = port;
632+
633633
if (!port->grp_lock) {
634634
/* Create group lock if it does not have one */
635635
pjmedia_port_init_grp_lock(port, pool, NULL);
@@ -845,27 +845,11 @@ static pj_status_t create_conf_port( pj_pool_t *parent_pool,
845845

846846
on_return:
847847
if (status != PJ_SUCCESS) {
848-
if (conf_port) {
849-
/* Destroy resample if this conf port has it. */
850-
if (conf_port->rx_resample)
851-
pjmedia_resample_destroy(conf_port->rx_resample);
852-
853-
if (conf_port->tx_resample)
854-
pjmedia_resample_destroy(conf_port->tx_resample);
855-
856-
if (conf_port->tx_lock)
857-
CONF_CHECK_SUCCESS(pj_lock_destroy(conf_port->tx_lock),(void)0);
858-
if (conf_port->free_node_cache)
859-
CONF_CHECK_SUCCESS(pj_atomic_slist_destroy(conf_port->free_node_cache),(void)0);
860-
if (conf_port->buff_to_mix)
861-
CONF_CHECK_SUCCESS(pj_atomic_slist_destroy(conf_port->buff_to_mix),(void)0);
862-
if (conf_port->requests_to_mix)
863-
CONF_CHECK_SUCCESS(pj_atomic_destroy(conf_port->requests_to_mix),(void)0);
864-
865-
//TODO grp_lock ?
866-
}
867-
if (pool)
868-
pj_pool_release(pool);
848+
/* Decrease conf port ref count */
849+
if (conf_port->port && conf_port->port->grp_lock)
850+
pj_grp_lock_dec_ref(conf_port->port->grp_lock);
851+
else
852+
destroy_conf_port(conf_port);
869853
}
870854

871855
return status;
@@ -2478,6 +2462,13 @@ static void destroy_conf_port( struct conf_port *conf_port )
24782462
if (conf_port->tx_lock != NULL)
24792463
pj_lock_destroy(conf_port->tx_lock);
24802464

2465+
if (conf_port->free_node_cache)
2466+
pj_atomic_slist_destroy(conf_port->free_node_cache);
2467+
if (conf_port->buff_to_mix)
2468+
pj_atomic_slist_destroy(conf_port->buff_to_mix);
2469+
if (conf_port->requests_to_mix)
2470+
pj_atomic_destroy(conf_port->requests_to_mix);
2471+
24812472
pj_pool_safe_release(&conf_port->pool);
24822473
}
24832474

pjmedia/src/pjmedia/conference.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,12 @@ static pj_status_t create_conf_port( pj_pool_t *parent_pool,
403403

404404
/* Create own pool */
405405
pool = pj_pool_create(parent_pool->factory, pname, 500, 500, NULL);
406-
if (!pool) {
407-
status = PJ_ENOMEM;
408-
goto on_return;
409-
}
406+
if (!pool)
407+
return PJ_ENOMEM;
410408

411409
/* Create port. */
412410
conf_port = PJ_POOL_ZALLOC_T(pool, struct conf_port);
413-
PJ_ASSERT_ON_FAIL(conf_port, {status = PJ_ENOMEM; goto on_return;});
411+
PJ_ASSERT_ON_FAIL(conf_port, {pj_pool_release(pool); return PJ_ENOMEM;});
414412
conf_port->pool = pool;
415413

416414
/* Increment port ref count to avoid premature destroy due to
@@ -614,8 +612,11 @@ static pj_status_t create_conf_port( pj_pool_t *parent_pool,
614612
if (conf_port && conf_port->tx_resample)
615613
pjmedia_resample_destroy(conf_port->tx_resample);
616614

617-
if (pool)
615+
if (port && port->grp_lock) {
616+
pj_grp_lock_dec_ref(port->grp_lock);
617+
} else if (pool) {
618618
pj_pool_release(pool);
619+
}
619620
}
620621

621622
return status;

0 commit comments

Comments
 (0)