Skip to content

fix: prevent crash when loadarchive#387

Merged
max-lvs merged 1 commit intolinuxdeepin:release/eaglefrom
LiHua000:release/eagle
Apr 14, 2026
Merged

fix: prevent crash when loadarchive#387
max-lvs merged 1 commit intolinuxdeepin:release/eaglefrom
LiHua000:release/eagle

Conversation

@LiHua000
Copy link
Copy Markdown
Contributor

@LiHua000 LiHua000 commented Apr 14, 2026

Log: as title

Summary by Sourcery

Bug Fixes:

  • Fix potential crash when scheduling archive loading with a delayed timer on Wayland by ensuring the file path remains valid for the callback.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 14, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR fixes a crash when loading an archive by correcting the lambda capture in a deferred QTimer callback so that the archive path remains valid when loadArchive is invoked.

Sequence diagram for deferred archive loading with QTimer

sequenceDiagram
    participant MainWindow
    participant QTimer

    MainWindow->>QTimer: singleShot(200, lambda(path))
    activate QTimer
    QTimer-->>MainWindow: invoke lambda(path)
    deactivate QTimer
    MainWindow->>MainWindow: loadArchive(path)
Loading

Class diagram for MainWindow archive loading methods

classDiagram
    class MainWindow {
        +bool handleArguments_Open(listParam: QStringList)
        +void loadArchive(path: QString)
    }

    class QTimer {
        +static void singleShot(msec: int, receiver: QObject, member: Pointer)
    }

    MainWindow ..> QTimer : uses
Loading

File-Level Changes

Change Details Files
Fix lambda capture for deferred archive loading to avoid dangling reference and crash.
  • Change QTimer::singleShot lambda capture of the archive path from reference to value so the path is safely copied for asynchronous use
  • Ensure loadArchive is called with a stable QString after the 200 ms delay on Wayland during first application load
src/source/mainwindow.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/source/mainwindow.cpp" line_range="2613" />
<code_context>
         firstLoad = false;
         auto path = listParam[0];
-        QTimer::singleShot(200, [this, &path]() {
+        QTimer::singleShot(200, [this, path]() {
             loadArchive(path);
         });
</code_context>
<issue_to_address>
**issue (bug_risk):** Use a QObject context or a safe pointer instead of capturing `this` in a delayed lambda to avoid potential use-after-free.

Because this runs 200 ms later without a QObject context, `this` may already be destroyed (e.g., if the window closes quickly), leading to a use-after-free in `loadArchive(path)`. Please use the `QTimer::singleShot` overload that takes a QObject context, or capture a `QPointer<MainWindow>` and check it before calling `loadArchive`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/source/mainwindow.cpp
firstLoad = false;
auto path = listParam[0];
QTimer::singleShot(200, [this, &path]() {
QTimer::singleShot(200, [this, path]() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Use a QObject context or a safe pointer instead of capturing this in a delayed lambda to avoid potential use-after-free.

Because this runs 200 ms later without a QObject context, this may already be destroyed (e.g., if the window closes quickly), leading to a use-after-free in loadArchive(path). Please use the QTimer::singleShot overload that takes a QObject context, or capture a QPointer<MainWindow> and check it before calling loadArchive.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LiHua000, max-lvs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@max-lvs max-lvs merged commit 8d26d14 into linuxdeepin:release/eagle Apr 14, 2026
16 checks passed
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.

3 participants