Create the port pool in MediaRosterUndertaker

Follow up to #15135, which created a regression, apps would crash if
using the port pool before creating a BMediaRoster instance. Now the
port pool is entirely managed by the MediaRosterUndertaker, which is
less confusing.

Fixes the media_addon_server crash on shutdown for me as well, but I
don't remember why (I had studied the code and came to the conclusion
that this should fix it, but I don't remember the reasoning).

Fixes #15263, and regressions for apps using the port pool before they
instanciate the BMediaRoster.

Change-Id: I887dbc590d8ee9de391b6eae0206944bfe99325f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1897
Reviewed-by: Axel Dörfler <axeld@pinc-software.de>
This commit is contained in:
Adrien Destugues 2019-10-05 14:46:48 +02:00 committed by Axel Dörfler
parent 9ecbb6ada1
commit 083314c2cb
2 changed files with 10 additions and 4 deletions

View File

@ -115,8 +115,17 @@ static BLocker sInitLocker("BMediaRoster::Roster locker");
static List<LocalNode> sRegisteredNodes;
// This class takes care of all static initialization and destruction of
// libmedia objects. It guarantees that things are created and destroyed in
// the correct order, as well as performing some "garbage collecting" by being
// destructed automatically on application exit.
class MediaRosterUndertaker {
public:
MediaRosterUndertaker()
{
gPortPool = new PortPool();
}
~MediaRosterUndertaker()
{
BAutolock _(sInitLocker);
@ -169,9 +178,6 @@ BMediaRosterEx::BMediaRosterEx(status_t* _error)
{
gDormantNodeManager = new DormantNodeManager();
gTimeSourceObjectManager = new TimeSourceObjectManager();
gPortPool = new PortPool();
// This is created here but deleted in the MediaRosterUndertaker because
// otherwise there are segfaults trying to send final quit messages.
*_error = BuildConnections();

View File

@ -19,7 +19,7 @@ namespace media {
PortPool* gPortPool;
// initialized by BMediaRosterEx, deleted by MediaRosterUndertaker.
// managed by MediaRosterUndertaker.
PortPool::PortPool()