From 083314c2cbfa9459cfc3e55873f04050f238be90 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sat, 5 Oct 2019 14:46:48 +0200 Subject: [PATCH] Create the port pool in MediaRosterUndertaker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/kits/media/MediaRoster.cpp | 12 +++++++++--- src/kits/media/PortPool.cpp | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp index f3ae2ad7ea..1f907ab91e 100644 --- a/src/kits/media/MediaRoster.cpp +++ b/src/kits/media/MediaRoster.cpp @@ -115,8 +115,17 @@ static BLocker sInitLocker("BMediaRoster::Roster locker"); static List 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(); diff --git a/src/kits/media/PortPool.cpp b/src/kits/media/PortPool.cpp index e19e3fcdb0..4418de5b03 100644 --- a/src/kits/media/PortPool.cpp +++ b/src/kits/media/PortPool.cpp @@ -19,7 +19,7 @@ namespace media { PortPool* gPortPool; - // initialized by BMediaRosterEx, deleted by MediaRosterUndertaker. + // managed by MediaRosterUndertaker. PortPool::PortPool()