From 4e915e0b5e1883762f1a59b7df486056b4e7bf10 Mon Sep 17 00:00:00 2001
From: Gavin Hurlbut <ghurlbut@mythtv.org>
Date: Thu, 3 Feb 2011 22:22:04 -0800
Subject: [PATCH] Change to using QPointer so double delete issues stop
We keep on seem to get some race conditions with myth_system launched things
exiting too fast (i.e. command not found, fast crashes) and causing a set of
race conditions involving deleting the MythSystemUnix item when the process
ends. The use of QPointer should avoid these problems as when a QPointer item
is deleted, the reference is automatically zeroed, even if it was deleted
elsewhere (or so the docs seem to say). With that plus a few more null checks
and we can avoid using it after it's freed.
---
mythtv/libs/libmythbase/system-unix.cpp | 6 ++++++
mythtv/libs/libmythbase/system-unix.h | 5 +++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/mythtv/libs/libmythbase/system-unix.cpp b/mythtv/libs/libmythbase/system-unix.cpp
index 2c43a4c..9b64d08 100644
a
|
b
|
void MythSystemManager::run(void) |
335 | 335 | next = i + 1; |
336 | 336 | pid = i.key(); |
337 | 337 | ms = i.value(); |
| 338 | if (!ms) |
| 339 | continue; |
338 | 340 | |
339 | 341 | // handle processes beyond marked timeout |
340 | 342 | if( ms->m_timeout > 0 && ms->m_timeout < now ) |
… |
… |
void MythSystemSignalManager::run(void) |
443 | 445 | MythSystemUnix *ms = msList.takeFirst(); |
444 | 446 | listLock.unlock(); |
445 | 447 | |
| 448 | // This can happen if it has been deleted already |
| 449 | if (!ms) |
| 450 | continue; |
| 451 | |
446 | 452 | ms->m_parent->HandlePostRun(); |
447 | 453 | |
448 | 454 | if (ms->m_stdpipe[0] > 0) |
diff --git a/mythtv/libs/libmythbase/system-unix.h b/mythtv/libs/libmythbase/system-unix.h
index 0785559..7279811 100644
a
|
b
|
|
10 | 10 | #include <QThread> |
11 | 11 | #include <QWaitCondition> |
12 | 12 | #include <QMutex> |
| 13 | #include <QPointer> |
13 | 14 | #include <sys/select.h> |
14 | 15 | #include "mythsystem.h" |
15 | 16 | |
16 | 17 | class MythSystemUnix; |
17 | 18 | |
18 | | typedef QMap<pid_t, MythSystemUnix *> MSMap_t; |
| 19 | typedef QMap<pid_t, QPointer<MythSystemUnix> > MSMap_t; |
19 | 20 | typedef QMap<int, QBuffer *> PMap_t; |
20 | | typedef QList<MythSystemUnix *> MSList_t; |
| 21 | typedef QList<QPointer<MythSystemUnix> > MSList_t; |
21 | 22 | |
22 | 23 | class MythSystemIOHandler: public QThread |
23 | 24 | { |