Skip to content

fix: memory leak in prelaunch splash#746

Open
misaka18931 wants to merge 1 commit intolinuxdeepin:masterfrom
misaka18931:master
Open

fix: memory leak in prelaunch splash#746
misaka18931 wants to merge 1 commit intolinuxdeepin:masterfrom
misaka18931:master

Conversation

@misaka18931
Copy link
Collaborator

@misaka18931 misaka18931 commented Feb 12, 2026

The PrelaunchSplash handler in ShellHandler does not properly unlock the wlr_buffer it received when it decides to skip the splash. Coincidentally, WindowConfigStore decided to lock the buffer again while waiting for the DConfig object to initialize, which was unnecessary, since the buffer would have been locked by wlr_buffer_try_from_resource, and erroneous as it failed to unlock it after.

These issues combined will cause all icon buffers that are displayed, plus some which fails to do so, to leak memory, until treeland terminates.

Summary by Sourcery

Fix memory leaks and unnecessary buffer locking in the prelaunch splash handling flow.

Bug Fixes:

  • Ensure icon buffers are always unlocked when prelaunch splash is skipped, preventing leaks.
  • Avoid redundant buffer locking while waiting for splash configuration to load.

Enhancements:

  • Simplify prelaunch splash request handling by consolidating early-return conditions and removing the wait callback from the window configuration workflow.

The PrelaunchSplash handler in ShellHandler does not properly unlock the
wlr_buffer it received when it decides to skip the splash.
Coincidentally, WindowConfigStore decided to lock the buffer again while
waiting for the DConfig object to initialize, which was unnecessary,
since the buffer would have been locked by wlr_buffer_try_from_resource,
and erroneous as it failed to unlock it after.

These issues combined will cause all icon buffers that are displayed,
plus some which fails to do so, to leak memory, until treeland
terminates.
Copilot AI review requested due to automatic review settings February 12, 2026 13:06
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: misaka18931

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

@misaka18931 misaka18931 requested review from wineee and zccrs and removed request for Copilot February 12, 2026 13:06
@sourcery-ai
Copy link

sourcery-ai bot commented Feb 12, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes a memory leak in the prelaunch splash flow by ensuring icon buffers are always unlocked when the splash is skipped and by removing an unnecessary lock during configuration loading, simplifying the control flow between ShellHandler and WindowConfigStore.

Sequence diagram for updated prelaunch splash handling

sequenceDiagram
    actor Client
    participant ShellHandler
    participant WindowConfigStore
    participant IconBuffer as iconBuffer

    Client->>ShellHandler: handlePrelaunchSplashRequested(appId, iconBuffer)

    alt prelaunch_disabled_or_invalid_or_duplicate
        ShellHandler->>IconBuffer: unlock()
        ShellHandler->>ShellHandler: m_pendingPrelaunchAppIds.remove(appId)
        ShellHandler-->>Client: return
    else prelaunch_enabled_and_valid
        ShellHandler->>ShellHandler: m_pendingPrelaunchAppIds.insert(appId)
        ShellHandler->>WindowConfigStore: withSplashConfigFor(appId, context, callback, skipCallback)

        alt no_config_or_dconfig_disabled_or_invalid_theme
            WindowConfigStore->>ShellHandler: skipCallback()
            ShellHandler->>IconBuffer: unlock()
            ShellHandler->>ShellHandler: m_pendingPrelaunchAppIds.remove(appId)
        else config_ready
            WindowConfigStore-->>ShellHandler: callback(appId, dconfigPath, darkPalette, lightPalette, splashThemeType)
            ShellHandler->>ShellHandler: createPrelaunchSplash(appId, ...)
        end
    end
Loading

Updated class diagram for ShellHandler and WindowConfigStore interaction

classDiagram
    class ShellHandler {
        - QList~SurfaceWrapper*~ m_prelaunchWrappers
        - QSet~QString~ m_pendingPrelaunchAppIds
        - WindowConfigStore* m_windowConfigStore
        - AppIdResolverManager* m_appIdResolverManager
        + void handlePrelaunchSplashRequested(QString appId, qw_buffer* iconBuffer)
        + void createPrelaunchSplash(QString appId, QString dconfigPath, QString darkPalette, QString lightPalette, qlonglong splashThemeType)
    }

    class WindowConfigStore {
        + void withSplashConfigFor(QString appId,
                                  QObject* context,
                                  std::function~void(QString appId, QString dconfigPath, QString darkPalette, QString lightPalette, qlonglong splashThemeType)~ callback,
                                  std::function~void()~ skipCallback) const
        - AppConfig* configForApp(QString appId) const
    }

    class iconBuffer

    ShellHandler --> WindowConfigStore : uses
    ShellHandler --> iconBuffer : manages_lock_unlock
Loading

File-Level Changes

Change Details Files
Ensure icon buffer is always unlocked when prelaunch splash is skipped and simplify early-return conditions.
  • Replace multiple early returns in the prelaunch splash handler with a single compound condition that funnels failures through a skipSplash lambda
  • Call skipSplash before returning when conditions to show a prelaunch splash are not met, guaranteeing iconBuffer->unlock() is invoked when needed
  • Defer insertion of appId into m_pendingPrelaunchAppIds until after all early-exit checks have passed
src/core/shellhandler.cpp
Remove unnecessary buffer lock during splash configuration wait and simplify API between ShellHandler and WindowConfigStore.
  • Remove the waitSplash lambda that locked the icon buffer without unlocking it later
  • Change WindowConfigStore::withSplashConfigFor to no longer accept or require a waitCallback and drop its invocation
  • Update the withSplashConfigFor declaration in the header to match the new two-callback signature
src/core/shellhandler.cpp
src/core/windowconfigstore.cpp
src/core/windowconfigstore.h

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

@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 reviewed your changes and they look great!


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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a memory leak in the prelaunch splash handling mechanism where icon buffers were not being properly managed. The issue was caused by unnecessary buffer locking in the WindowConfigStore while waiting for DConfig initialization, combined with missing unlock calls when the splash is skipped.

Changes:

  • Removed the waitCallback parameter from withSplashConfigFor method that was unnecessarily locking buffers
  • Restructured early return conditions in handlePrelaunchSplashRequested to ensure the unlock callback is always called when skipping splash creation
  • Removed unused #include <utility> header

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/core/windowconfigstore.h Removed waitCallback parameter from withSplashConfigFor method signature
src/core/windowconfigstore.cpp Removed waitCallback implementation, assertions, and the redundant buffer lock call
src/core/shellhandler.cpp Restructured logic to call skipSplash() (which unlocks buffer) in all early-return paths; removed unused header

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