Skip to content

Commit fe225f2

Browse files
ann0seesoftins
andcommitted
Fix memory leak found by copilot
Co-authored-by: softins <softins@users.noreply.github.com> See: #3702
1 parent 76fc757 commit fe225f2

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/clientdlg.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,13 @@ void CClientDlg::OnChatTextReceived ( QString strChatText )
876876
{
877877
if ( pSettings->bEnableAudioAlerts )
878878
{
879-
QSoundEffect* sf = new QSoundEffect();
879+
QSoundEffect* sf = new QSoundEffect ( this );
880+
connect ( sf, &QSoundEffect::playingChanged, this, [sf]() {
881+
if ( !sf->isPlaying() )
882+
{
883+
sf->deleteLater();
884+
}
885+
} );
880886
sf->setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_message.wav" ) );
881887
sf->play();
882888
}
@@ -927,7 +933,13 @@ void CClientDlg::OnNumClientsChanged ( int iNewNumClients )
927933
{
928934
if ( pSettings->bEnableAudioAlerts && iNewNumClients > iClients )
929935
{
930-
QSoundEffect* sf = new QSoundEffect();
936+
QSoundEffect* sf = new QSoundEffect ( this );
937+
connect ( sf, &QSoundEffect::playingChanged, this, [sf]() {
938+
if ( !sf->isPlaying() )
939+
{
940+
sf->deleteLater();
941+
}
942+
} );
931943
sf->setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_user.wav" ) );
932944
sf->play();
933945
}

0 commit comments

Comments
 (0)