Skip to content

Commit

Permalink
Hopefully fix a rare segfault in MythUITextEdit when using mythmusic.…
Browse files Browse the repository at this point in the history
… I'm guessing but by no means certain that a linked copy of the string was altered in another thread, e.g. the metadata or playlist load thread. QString uses shallow copies and isn't threadsafe. detaching the string may use more memory but that's preferable to crashing.
  • Loading branch information
stuartm committed Jan 31, 2013
1 parent 479d2a8 commit 3bb0d2c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion mythtv/libs/libmythui/mythuitext.cpp
Expand Up @@ -128,6 +128,7 @@ void MythUIText::Reset()
void MythUIText::SetText(const QString &text)
{
QString newtext = text;
newtext.detach();

if (!m_Layouts.isEmpty() && newtext == m_Message)
return;
Expand Down Expand Up @@ -203,7 +204,9 @@ void MythUIText::SetTextFromMap(QHash<QString, QString> &map)

QString MythUIText::GetText(void) const
{
return m_Message;
QString ret = m_Message;
ret.detach();
return ret;
}

QString MythUIText::GetDefaultText(void) const
Expand Down
8 changes: 8 additions & 0 deletions mythtv/libs/libmythui/mythuitextedit.cpp
Expand Up @@ -219,6 +219,7 @@ void MythUITextEdit::SetText(const QString &text, bool moveCursor)
return;

m_Message = text;
m_Message.detach();

if (m_isPassword)
{
Expand All @@ -236,6 +237,13 @@ void MythUITextEdit::SetText(const QString &text, bool moveCursor)
emit valueChanged();
}

QString MythUITextEdit::GetText(void) const
{
QString ret = m_Message;
ret.detach();
return ret;
}

void MythUITextEdit::InsertText(const QString &text)
{
if (!m_Text)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythuitextedit.h
Expand Up @@ -43,7 +43,7 @@ class MUI_PUBLIC MythUITextEdit : public MythUIType, public StorageUser

void SetText(const QString &text, bool moveCursor = true);
void InsertText(const QString &text);
QString GetText(void) const { return m_Message; }
QString GetText(void) const;

void SetFilter(InputFilter filter) { m_Filter = filter; }
void SetPassword(bool isPassword) { m_isPassword = isPassword; }
Expand Down

0 comments on commit 3bb0d2c

Please sign in to comment.