Skip to content

Commit

Permalink
Make LiveTVChain a reference counted object
Browse files Browse the repository at this point in the history
Under some circumstances, the LiveTVChain instance could have been deleted by the backend MainServer, yet would continue to be used by TVRec.
I'm no fan of reference counted objects, it's only a workaround over an architecture problem, but at this stage; it's the easiest fix

Fixes #11661
  • Loading branch information
jyavenard committed Jul 11, 2013
1 parent 6749fee commit 93488a2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion mythtv/libs/libmythtv/livetvchain.cpp
Expand Up @@ -23,16 +23,18 @@ static inline void clear(LiveTVChainEntry &entry)
/** \class LiveTVChain
* \brief Keeps track of recordings in a current LiveTV instance
*/
LiveTVChain::LiveTVChain() :
LiveTVChain::LiveTVChain() : ReferenceCounter("LiveTVChain"),
m_id(""), m_maxpos(0), m_lock(QMutex::Recursive),
m_curpos(0), m_cur_chanid(0),
m_switchid(-1), m_jumppos(0)
{
clear(m_switchentry);
LOG(VB_GENERAL, LOG_DEBUG, LOC + "ctor");
}

LiveTVChain::~LiveTVChain()
{
LOG(VB_GENERAL, LOG_DEBUG, LOC + "dtor");
}

QString LiveTVChain::InitializeNewChain(const QString &seed)
Expand Down
4 changes: 3 additions & 1 deletion mythtv/libs/libmythtv/livetvchain.h
Expand Up @@ -8,6 +8,8 @@
#include <QList>

#include "mythtvexp.h"
#include "referencecounter.h"


class ProgramInfo;
class MythSocket;
Expand All @@ -24,7 +26,7 @@ struct MTV_PUBLIC LiveTVChainEntry
QString inputname;
};

class MTV_PUBLIC LiveTVChain
class MTV_PUBLIC LiveTVChain : public ReferenceCounter
{
public:
LiveTVChain();
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/playercontext.cpp
Expand Up @@ -822,7 +822,7 @@ void PlayerContext::SetTVChain(LiveTVChain *chain)
if (tvchain)
{
tvchain->DestroyChain();
delete tvchain;
tvchain->DecrRef();
tvchain = NULL;
}

Expand Down
6 changes: 6 additions & 0 deletions mythtv/libs/libmythtv/tv_rec.cpp
Expand Up @@ -588,6 +588,7 @@ RecStatusType TVRec::StartRecording(const ProgramInfo *pginfo)
QString message = QString("LIVETV_EXITED");
MythEvent me(message, tvchain->GetID());
gCoreContext->dispatch(me);
tvchain->DecrRef();
tvchain = NULL;
}

Expand Down Expand Up @@ -2605,6 +2606,7 @@ void TVRec::SpawnLiveTV(LiveTVChain *newchain, bool pip, QString startchan)
QMutexLocker lock(&stateChangeLock);

tvchain = newchain;
tvchain->IncrRef(); // mark it for TVRec use
tvchain->ReloadAll();

QString hostprefix = gCoreContext->GenMythURL(
Expand Down Expand Up @@ -2862,6 +2864,10 @@ void TVRec::StopLiveTV(void)
WaitForEventThreadSleep();

// We are done with the tvchain...
if (tvchain)
{
tvchain->DecrRef();
}
tvchain = NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythbackend/mainserver.cpp
Expand Up @@ -6089,7 +6089,7 @@ void MainServer::DeleteChain(LiveTVChain *chain)
}
liveTVChains = newChains;

delete chain;
chain->DecrRef();
}

void MainServer::SetExitCode(int exitCode, bool closeApplication)
Expand Down

0 comments on commit 93488a2

Please sign in to comment.