Skip to content

Commit

Permalink
Fix potential null pointer dereferences in mythsocketmanager.
Browse files Browse the repository at this point in the history
Recent changes to Qt6 or the compiler have produced new null pointer
dereference warnings.  Apparently every call to a begin()/find()
function has a code path that can return the end() iterator (which
makes sense), and dereferencing the end() iterator in Qt6 is a null
pointer dereference.  This means that any call to a function returning
an iterator must be followed by a validity test before dereferencing
that iterator.  Prior checks for !empty() do not help, as another
thread could have removed the last item between the time of the empty
check and the time of the begin call.

Rewrite the code to eliminate this warning.
  • Loading branch information
linuxdude42 committed Jul 12, 2023
1 parent 3b564a8 commit d198f11
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mythtv/libs/libmythprotoserver/mythsocketmanager.cpp
Expand Up @@ -65,10 +65,11 @@ MythSocketManager::~MythSocketManager()
m_handlerMap.clear();

QMutexLocker locker(&m_socketListLock);
while (!m_socketList.empty())
for (auto iter = m_socketList.begin();
iter != m_socketList.end();
iter = m_socketList.erase(iter))
{
(*m_socketList.begin())->DecrRef();
m_socketList.erase(m_socketList.begin());
(*iter)->DecrRef();
}
}

Expand Down

0 comments on commit d198f11

Please sign in to comment.