diff options
author | Robert Adam <krzmbrzl@gmail.com> | 2021-01-04 14:34:24 +0300 |
---|---|---|
committer | Robert Adam <krzmbrzl@gmail.com> | 2021-01-04 14:39:28 +0300 |
commit | cc3c8244996ffc37205f702ef451936cbb9e349c (patch) | |
tree | bb186c3885fbef88544e11cbd2abdf0fe95caca8 /src/mumble/UserLocalNicknameDialog.cpp | |
parent | 391ea23d0fb08ecaae96a4902faa712b2d254a11 (diff) |
FIX(client,ui): Crash by pressing Esc in nickname dialog
When having the dialog open that allows to set a custom nickname to
another client (UserLocalNicknameDialog) pressing Esc would crash
Mumble. This is due to the Esc key triggering the dialog's reject()
function in which the dialog's smart-pointer object is removed from a
global list and therefore goes out of scope.
This results in the dialog getting deleted, but since this is done in a
member function of the dialog, there is still code accessing the now
deleted object (in Qt's internals) and this is causing the segmentation
fault.
The fix is to use a custom deleter function for the dialog pointer that
instead of using delete on it, calls deleteLater() on it. Thus the
deletion of the object is left to Qt which can then do it at a point at
which it is done with it.
As this is something that could get useful in other locations as well,
the custom deleter function was outsourced into its own file.
Fixes #4666
Diffstat (limited to 'src/mumble/UserLocalNicknameDialog.cpp')
-rw-r--r-- | src/mumble/UserLocalNicknameDialog.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/mumble/UserLocalNicknameDialog.cpp b/src/mumble/UserLocalNicknameDialog.cpp index afb43bc88..9e59cd42d 100644 --- a/src/mumble/UserLocalNicknameDialog.cpp +++ b/src/mumble/UserLocalNicknameDialog.cpp @@ -17,7 +17,7 @@ UserLocalNicknameDialog::UserLocalNicknameDialog( unsigned int sessionId, - std::unordered_map< unsigned int, std::unique_ptr< UserLocalNicknameDialog > > &qmUserNicknameTracker) + std::unordered_map< unsigned int, NicknameDialogPtr > &qmUserNicknameTracker) : QDialog(nullptr), m_clientSession(sessionId), m_qmUserNicknameTracker(qmUserNicknameTracker) { setupUi(this); @@ -49,13 +49,14 @@ void UserLocalNicknameDialog::closeEvent(QCloseEvent *event) { void UserLocalNicknameDialog::present( unsigned int sessionId, - std::unordered_map< unsigned int, std::unique_ptr< UserLocalNicknameDialog > > &qmUserNicknameTracker) { + std::unordered_map< unsigned int, NicknameDialogPtr > &qmUserNicknameTracker) { if (qmUserNicknameTracker.find(sessionId) != qmUserNicknameTracker.end()) { qmUserNicknameTracker.at(sessionId)->show(); qmUserNicknameTracker.at(sessionId)->raise(); } else { - std::unique_ptr< UserLocalNicknameDialog > userNickname = - std::make_unique< UserLocalNicknameDialog >(sessionId, qmUserNicknameTracker); + // Make sure to use the custom deleter for QObjects that calls deleteLater() on them instead of using + // delete directly as the latter can lead to segmentation faults. + NicknameDialogPtr userNickname(new UserLocalNicknameDialog(sessionId, qmUserNicknameTracker), deleteQObject); userNickname->show(); qmUserNicknameTracker.insert(std::make_pair(sessionId, std::move(userNickname))); } |