Skip to content

Conversation

xmkg
Copy link
Member

@xmkg xmkg commented Mar 26, 2025

The make_confirmation_callback function takes the key argument as const ref, meaning that it'll be bound to an existing QString when the arg is QString, but a temporary QString would be constructed and bound to it when the "key" is not a QString. This is fine during the make_confirmation_callback's scope since const& extend the lifetime of the temporary, but passing that "const&" to a capture list of a lambda that'll be executed later does not extend the lifetime, hence leading to undefined behavior.

I believe this was not causing any issues in release builds because of the optimization level. The compiler is probably inlining the whole thing, so the QString is directly constructed into the lambda's body. I could only trigger this while running the unit tests in Windows, built with the Debug configuration.

The patch fixes this issue by taking QString as a value and moving that into the lambda capture.

MULTI-1907

The make_confirmation_callback function takes the key argument as
const ref, meaning that it'll be bound to an existing QString when
the arg is QString, but a temporary QString would be constructed and
bound to it when the "key" is not a QString. This is fine during the
make_confirmation_callback's scope since const& extend the lifetime
of the temporary, but passing that "const&" to a capture list of a lambda
that'll be executed later does not extend the lifetime, hence leading
to undefined behavior.

The patch fixes this issue by taking QString as a value and moving that
into the lambda capture.

Signed-off-by: Mustafa Kemal Gilor <mustafa.gilor@canonical.com>
@xmkg xmkg requested review from georgeliao and Sploder12 March 26, 2025 09:16
Copy link

codecov bot commented Mar 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.27%. Comparing base (5130efd) to head (8562520).
Report is 3520 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4004   +/-   ##
=======================================
  Coverage   89.27%   89.27%           
=======================================
  Files         259      259           
  Lines       14653    14653           
=======================================
  Hits        13081    13081           
  Misses       1572     1572           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@georgeliao
Copy link
Contributor

Good work, thanks for catching this.
The change looks sane to me.

Copy link
Contributor

@Sploder12 Sploder12 left a comment

Choose a reason for hiding this comment

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

Good catch!

@xmkg xmkg added this pull request to the merge queue Mar 26, 2025
@xmkg
Copy link
Member Author

xmkg commented Mar 26, 2025

Thanks for the prompt review @georgeliao @Sploder12 !

Merged via the queue into main with commit 7b8cabc Mar 26, 2025
16 checks passed
@xmkg xmkg deleted the bugfix/confirmation-callback-lambda-capture-lifetime branch March 26, 2025 18:49
@ricab ricab added this to the 1.16.0 milestone Jun 13, 2025
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.

4 participants