Skip to content

Potential fixes for 4 code quality findings#3702

Draft
ann0see wants to merge 4 commits into
mainfrom
ai-findings-autofix/src-clientdlg.cpp
Draft

Potential fixes for 4 code quality findings#3702
ann0see wants to merge 4 commits into
mainfrom
ai-findings-autofix/src-clientdlg.cpp

Conversation

@ann0see
Copy link
Copy Markdown
Member

@ann0see ann0see commented May 20, 2026

This PR applies 4/4 suggestions from code quality AI findings.

Only for review. We should then decide if we actually have a memory leak here.

ann0see and others added 4 commits May 20, 2026 20:24
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@ann0see
Copy link
Copy Markdown
Member Author

ann0see commented May 20, 2026

I don't think everything here is valid.

Comment thread src/clientdlg.cpp
Comment on lines +859 to +861
QSoundEffect sf;
sf.setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_message.wav" ) );
sf.play();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be valid. Stack vs heap allocation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> memory leak

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this won't work. The original does indeed have a memory leak, as the pointer returned from new QSoundEffect() is only local, and disappears at the end of the block. But I think changing it so that the QSoundEffect sf is allocated locally on the stack may cause a crash, or at least truncate the playback, as the object will be destroyed immediately at the end of the block while the sound is still playing.

The correct solution is actually the one shown below around line 910: connect a lambda to the playingChanged signal and call deleteLater() when it is finished with.

Comment thread src/clientdlg.cpp
@ann0see ann0see requested review from pljones and softins May 20, 2026 18:56
Comment thread src/clientdlg.cpp
Comment on lines +859 to +861
QSoundEffect sf;
sf.setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_message.wav" ) );
sf.play();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this won't work. The original does indeed have a memory leak, as the pointer returned from new QSoundEffect() is only local, and disappears at the end of the block. But I think changing it so that the QSoundEffect sf is allocated locally on the stack may cause a crash, or at least truncate the playback, as the object will be destroyed immediately at the end of the block while the sound is still playing.

The correct solution is actually the one shown below around line 910: connect a lambda to the playingChanged signal and call deleteLater() when it is finished with.

Comment thread src/clientdlg.cpp
Comment on lines +910 to +917
QSoundEffect* sf = new QSoundEffect ( this );
connect ( sf, &QSoundEffect::playingChanged, this, [sf]()
{
if ( !sf->isPlaying() )
{
sf->deleteLater();
}
} );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ok and is the correct way to avoid the memory leak.

Comment thread src/clientdlg.cpp
@ann0see ann0see mentioned this pull request May 29, 2026
5 tasks
ann0see pushed a commit to ann0see/jamulus that referenced this pull request May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants