From c408a02495cb92ad891fcef3d2a165792e2944fa Mon Sep 17 00:00:00 2001 From: ann0see <20726856+ann0see@users.noreply.github.com> Date: Tue, 9 Jun 2026 22:42:33 +0200 Subject: [PATCH 1/2] Fix memory leak found by copilot Co-authored-by: softins See: https://github.com/jamulussoftware/jamulus/pull/3702 --- src/clientdlg.cpp | 8 ++------ src/clientdlg.h | 1 - src/util.cpp | 13 +++++++++++++ src/util.h | 4 ++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/clientdlg.cpp b/src/clientdlg.cpp index 09409d7eaf..b102c34724 100644 --- a/src/clientdlg.cpp +++ b/src/clientdlg.cpp @@ -876,9 +876,7 @@ void CClientDlg::OnChatTextReceived ( QString strChatText ) { if ( pSettings->bEnableAudioAlerts ) { - QSoundEffect* sf = new QSoundEffect(); - sf->setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_message.wav" ) ); - sf->play(); + PlayAudioAlert ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_message.wav" ) ); } ChatDlg.AddChatText ( strChatText ); @@ -927,9 +925,7 @@ void CClientDlg::OnNumClientsChanged ( int iNewNumClients ) { if ( pSettings->bEnableAudioAlerts && iNewNumClients > iClients ) { - QSoundEffect* sf = new QSoundEffect(); - sf->setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_user.wav" ) ); - sf->play(); + PlayAudioAlert ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_user.wav" ) ); } // iNewNumClients will be zero on the first trigger of this signal handler when connecting to a new server. diff --git a/src/clientdlg.h b/src/clientdlg.h index 687fe811f4..6a34cc66f0 100644 --- a/src/clientdlg.h +++ b/src/clientdlg.h @@ -60,7 +60,6 @@ #include #include #include -#include #if QT_VERSION >= QT_VERSION_CHECK( 5, 6, 0 ) # include #endif diff --git a/src/util.cpp b/src/util.cpp index 90b1506206..6afcb0c45b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1679,3 +1679,16 @@ QString TruncateString ( QString str, int position ) } return str.left ( position ); } + +void PlayAudioAlert ( QUrl soundUrl ) +{ + QSoundEffect* sf = new QSoundEffect(); + QObject::connect ( sf, &QSoundEffect::playingChanged, sf, [sf]() { + if ( !sf->isPlaying() ) + { + sf->deleteLater(); + } + } ); + sf->setSource ( soundUrl ); + sf->play(); +} diff --git a/src/util.h b/src/util.h index c104d7ede7..71c1478041 100644 --- a/src/util.h +++ b/src/util.h @@ -75,6 +75,8 @@ #include #include #include +#include + #ifndef DISABLE_SRV_DNS # include #endif @@ -1407,3 +1409,5 @@ struct EnumClassHash } }; #endif + +void PlayAudioAlert ( QUrl soundUrl ); From 30a13b9f5e15d02bd96d31eac2152387c0a5c153 Mon Sep 17 00:00:00 2001 From: Tony Mountifield Date: Wed, 10 Jun 2026 00:21:18 +0100 Subject: [PATCH 2/2] Move QSoundEffect and PlayAudioAlert to gui sections --- src/util.cpp | 26 +++++++++++++------------- src/util.h | 6 +++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 6afcb0c45b..eba8ce47a4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -758,6 +758,19 @@ QSize CMinimumStackedLayout::sizeHint() const } return QStackedLayout::sizeHint(); } + +void PlayAudioAlert ( QUrl soundUrl ) +{ + QSoundEffect* sf = new QSoundEffect(); + QObject::connect ( sf, &QSoundEffect::playingChanged, sf, [sf]() { + if ( !sf->isPlaying() ) + { + sf->deleteLater(); + } + } ); + sf->setSource ( soundUrl ); + sf->play(); +} #endif /******************************************************************************\ @@ -1679,16 +1692,3 @@ QString TruncateString ( QString str, int position ) } return str.left ( position ); } - -void PlayAudioAlert ( QUrl soundUrl ) -{ - QSoundEffect* sf = new QSoundEffect(); - QObject::connect ( sf, &QSoundEffect::playingChanged, sf, [sf]() { - if ( !sf->isPlaying() ) - { - sf->deleteLater(); - } - } ); - sf->setSource ( soundUrl ); - sf->play(); -} diff --git a/src/util.h b/src/util.h index 71c1478041..84ce8e3261 100644 --- a/src/util.h +++ b/src/util.h @@ -75,7 +75,6 @@ #include #include #include -#include #ifndef DISABLE_SRV_DNS # include @@ -96,6 +95,7 @@ # include # include # include +# include # include "ui_aboutdlgbase.h" #endif @@ -491,6 +491,8 @@ class CMinimumStackedLayout : public QStackedLayout CMinimumStackedLayout ( QWidget* parent = nullptr ) : QStackedLayout ( parent ) {} virtual QSize sizeHint() const override; }; + +void PlayAudioAlert ( QUrl soundUrl ); #endif /******************************************************************************\ @@ -1409,5 +1411,3 @@ struct EnumClassHash } }; #endif - -void PlayAudioAlert ( QUrl soundUrl );