Skip to content

Commit ff14307

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 ff14307

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/clientdlg.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,14 @@ 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+
{
882+
if ( !sf->isPlaying() )
883+
{
884+
sf->deleteLater();
885+
}
886+
} );
880887
sf->setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_message.wav" ) );
881888
sf->play();
882889
}
@@ -927,7 +934,14 @@ void CClientDlg::OnNumClientsChanged ( int iNewNumClients )
927934
{
928935
if ( pSettings->bEnableAudioAlerts && iNewNumClients > iClients )
929936
{
930-
QSoundEffect* sf = new QSoundEffect();
937+
QSoundEffect* sf = new QSoundEffect( this );
938+
connect ( sf, &QSoundEffect::playingChanged, this, [sf]()
939+
{
940+
if ( !sf->isPlaying() )
941+
{
942+
sf->deleteLater();
943+
}
944+
} );
931945
sf->setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_user.wav" ) );
932946
sf->play();
933947
}

0 commit comments

Comments
 (0)