fetzerch / xbmc-pvr-addons

XBMC PVR add-ons
GNU General Public License v3.0
19 stars 17 forks source link

[mythtv-cmyth] Return shared pointers in MythScheduleManager #145

Closed fetzerch closed 10 years ago

fetzerch commented 10 years ago

In the current implementation, MythScheduleManager holds the upcoming recordings and recording rules in data structures that use smart pointers. However, these were always passed as raw pointers to the outside (pvrclient-mythtv).

With this patch, the API of the MythScheduleManager is changed to always pass data within smart pointers.

In rare cases, PVRClientMythTV::GetTimers() gets called while m_scheduleManager->Update() is still running. Update() cleared the list of upcoming recordings which deleted all MythProgramInfos since the only reference was held from the list. This could lead into GetTimers accessing freed memory.

Trace: 0x4809f534 in cmyth_proginfo_start () from /usr/lib/xbmc/addons/pvr.mythtv.cmyth/XBMC_MythTV_cmyth.pvr 0 0x4809f534 in cmyth_proginfo_start () from /usr/lib/xbmc/addons/pvr.mythtv.cmyth/XBMC_MythTVcmyth.pvr 1 0x48076ba8 in MythProgramInfo::StartTime (this=) at src/cppmyth/MythProgramInfo.cpp:147 2 0x4805ab9c in PVRClientMythTV::GetTimers (this=, handle=) at src/pvrclient-mythtv.cpp:934 3 0x004dc6b4 in PVR::CPVRClient::GetTimers(PVR::CPVRTimers) () 4 0x004ebaec in PVR::CPVRClients::GetTimers(PVR::CPVRTimers_) () 5 0x00bdb668 in PVR::CPVRTimers::Update() () 0x00bb5830 in PVR::CPVRManager::ExecutePendingJobs() () 7 0x00bbae00 in PVR::CPVRManager::Process() () 8 0x00ebc39c in CThread::Action() () 9 0x00ebce30 in CThread::staticThread(void*) () 10 0x405b2a90 in start_thread () from /lib/libpthread.so.0 11 0x41226fb8 in clone () from /lib/libc.so.6

@janbar: Maybe you remember, some time ago I told you about a very rare crash that I experience. with the ScheduleManager. I still don't have an easy way to reproduce it unfortunately. But it has been reported also here: http://forum.xbmc.org/showthread.php?tid=173932&pid=1529167#pid1529167 I tried to find a solution. I'll do a bit more testing and merge it then.

epienbroek commented 10 years ago

Hi,

For some time I was also having strange segfaults with the XBMC MythTV plugin (using OpenELEC 3.2 + updated xbmc-pvr-addons). Here's the segfault I got which looks similar to the one mentioned earlier in this ticket:

Program received signal SIGSEGV, Segmentation fault. [Switching to LWP 1135] 0xa8f9a8b8 in cmyth_proginfo_rec_start () from /usr/lib/xbmc/addons/pvr.mythtv.cmyth/XBMC_MythTV_cmyth.pvr (gdb) bt 0 0xa8f9a8b8 in cmyth_proginfo_rec_start () from /usr/lib/xbmc/addons/pvr.mythtv.cmyth/XBMC_MythTV_cmyth.pvr 1 0xa8f9a8d0 in MythProgramInfo::RecordingStartTime() () from /usr/lib/xbmc/addons/pvr.mythtv.cmyth/XBMC_MythTV_cmyth.pvr 2 0xa8fad8d4 in PVRClientMythTV::GetTimers(ADDON_HANDLESTRUCT) () from /usr/lib/xbmc/addons/pvr.mythtv.cmyth/XBMC_MythTVcmyth.pvr 3 0x006e4978 in PVR::CPVRClient::GetTimers(PVR::CPVRTimers) () 4 0x006ec6c0 in PVR::CPVRClients::GetTimers(PVR::CPVRTimers) () 5 0x004a0f00 in PVR::CPVRTimers::Update() () 6 0x0048f490 in PVR::CPVRManager::ExecutePendingJobs() () 7 0x00490088 in PVR::CPVRManager::Process() () 8 0x0086d670 in CThread::Action() () 9 0x0086e0e0 in CThread::staticThread(void) () 10 0xb6ea7cd8 in ?? () from /usr/lib/libpthread.so.0 11 0xb6ea7cd8 in ?? () from /usr/lib/libpthread.so.0 Backtrace stopped: previous frame identical to this frame (corrupt stack?)

For me the segfault can be reproduced pretty reliable. It always seems to happen when the MythTV backend auto-expires old recording (due to lack of disk space).

I just applied the patch mentioned in this ticket and the segfault doesn't happen any more on my environment. (although I only did some short testing). I'll leave everything running to make sure the issue really is resolved, but things look good so far.

fetzerch commented 10 years ago

Thanks for testing! Pushed to master (579e8a6b6a5dc850ccdb229aea25cf48a80cf307) and to frodo (36cd0741a5c860c16ef611f52c0171d794f6b57d).