Skip to content

Commit

Permalink
Make it so the second frontend won't crash
Browse files Browse the repository at this point in the history
If for some reason, a user decides to run two frontends on the same box, and
forget to set the service port to something non-standard for the second one,
we want it to at least not crash.

With this commit, it will just give up on running a webserver on the second run
frontend, but it will run.

Several tweaks were necessary to make the deleted webserver not double-free
and not otherwise corrupt memory.
  • Loading branch information
Beirdo committed Feb 9, 2011
1 parent 287de3d commit aba1fb0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
3 changes: 1 addition & 2 deletions mythtv/libs/libmythupnp/httpserver.cpp
Expand Up @@ -94,8 +94,7 @@ HttpServer::~HttpServer()
{
while (!m_extensions.empty())
{
delete m_extensions.back();
m_extensions.pop_back();
delete m_extensions.takeFirst();
}
}

Expand Down
6 changes: 4 additions & 2 deletions mythtv/libs/libmythupnp/httpserver.h
Expand Up @@ -57,8 +57,10 @@ class HttpServer;
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

class UPNP_PUBLIC HttpServerExtension
class UPNP_PUBLIC HttpServerExtension : public QObject
{
Q_OBJECT

public:

QString m_sName;
Expand All @@ -77,7 +79,7 @@ class UPNP_PUBLIC HttpServerExtension
// virtual bool Uninitialize ( ) = 0;
};

typedef QList<HttpServerExtension*> HttpServerExtensionList;
typedef QList<QPointer<HttpServerExtension> > HttpServerExtensionList;

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythupnp/threadpool.cpp
Expand Up @@ -405,7 +405,7 @@ WorkerThread *ThreadPool::GetWorkerThread()

WorkerThread *ThreadPool::AddWorkerThread( bool bMakeAvailable, long nTimeout )
{
QString sName = m_sName + "_WorkerThread";
QString sName = QString(m_sName + "_WorkerThread");
long nThreadCount;

VERBOSE( VB_UPNP, QString( "ThreadPool:AddWorkerThread - %1" ).arg( sName ));
Expand Down
7 changes: 5 additions & 2 deletions mythtv/libs/libmythupnp/threadpool.h
Expand Up @@ -33,6 +33,7 @@ using namespace std;
#include <QThread>
#include <QTimer>
#include <QObject>
#include <QPointer>

class ThreadPool;

Expand Down Expand Up @@ -107,7 +108,7 @@ class WorkerThread : public QThread
CEvent m_Initialized;
bool m_bInitialized;

ThreadPool *m_pThreadPool;
QPointer<ThreadPool> m_pThreadPool;

volatile bool m_bTermRequested;
QString m_sName;
Expand Down Expand Up @@ -148,8 +149,10 @@ class WorkerThread : public QThread

typedef deque<WorkerThread*> WorkerThreadList;

class ThreadPool
class ThreadPool : public QObject
{
Q_OBJECT

friend class WorkerThread;

protected:
Expand Down
5 changes: 5 additions & 0 deletions mythtv/programs/mythfrontend/main.cpp
Expand Up @@ -1273,6 +1273,11 @@ int main(int argc, char **argv)

gContext = new MythContext(MYTH_BINARY_VERSION);
g_pUPnp = new MediaRenderer();
if (!g_pUPnp->initialized())
{
delete g_pUPnp;
g_pUPnp = NULL;
}

// Override settings as early as possible to cover bootstrapped screens
// such as the language prompt
Expand Down
1 change: 1 addition & 0 deletions mythtv/programs/mythfrontend/mediarenderer.h
Expand Up @@ -44,6 +44,7 @@ class MediaRenderer : public UPnp
DeviceLocation *GetDefaultMaster();
void SetDefaultMaster( DeviceLocation *pDeviceLoc,
const QString &sPin );
bool initialized() { return (m_pHttpServer != NULL); }

};

Expand Down

0 comments on commit aba1fb0

Please sign in to comment.