https://bugs.kde.org/show_bug.cgi?id=525314

            Bug ID: 525314
           Summary: kwin_wayland leaks one kde_output_device_mode_v2
                    resource per advertised mode on every client re-bind
    Classification: Plasma
           Product: kwin
      Version First 6.7.4
       Reported In:
          Platform: CachyOS
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: wayland-generic
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

SUMMARY
=======

kwin_wayland leaks one kde_output_device_mode_v2 resource per advertised mode
every time a client re-binds the output device, and the resources are never
freed.

OutputDeviceV2InterfacePrivate::kde_output_device_v2_release() destroys only
the output device resource itself. The kde_output_device_mode_v2 resources
created for that resource in sendNewMode() are never destroyed, so every
re-bind leaks one server-side wl_resource (plus its QtWaylandServer wrapper)
per advertised mode. Wayland has no automatic parent-to-child resource
lifecycle, so they are orphaned until the client disconnects.

libkscreen-based clients re-bind on every configuration re-sync: kded6 (the
kscreen module) and powerdevil were observed re-binding continuously, so
kwin_wayland leaks in proportion to output-configuration churn.


OBSERVED IMPACT
===============

Live system: kwin 6.7.4, 13 days uptime, single 3440x1440 output advertising
42 modes.

- kwin_wayland RSS ~2.2 GB (normal for this setup: ~0.3 GB), peak 2.46 GB RSS
  plus 3.68 GB swap.
- gcore + glibc heap walk: 11.0 million chunks, of which 3,682,292 chunks of
  144 bytes are kde_output_device_mode_v2 wl_resources, and 1.93 million
  chunks of 48 bytes are the matching QtWaylandServer wrappers. Together that
  is 87% of all live heap (757 MB).
- Every leaked resource's wl_client back-pointer resolves to one of exactly
  two clients: pid 11151 (kded6) and pid 11194 (powerdevil), both libkscreen
  users.
- Secondary accumulation in the same re-sync loop (small): 87k
  wl_output::Resource wrappers, 57k zxdg_output_v1::Resource, 58k
  wp_image_description_v1::Resource.
- Growth is bursty, tracking output-configuration churn: flat for hours, then
  steps of +35 MB (screen blank/dim) and up to +440 MB (observed while kwin
  was stalled under ptrace and both daemons re-synced for its duration).


REPRODUCER
==========

The leak requires a long-lived client that re-binds without disconnecting;
short-lived tools like "kscreen-doctor --outputs" do NOT leak, because client
disconnect destroys all its wl_resources. In a normal session kded6 and
powerdevil do this continuously. To reproduce quickly, force
output-configuration churn so the daemons re-sync (each apply triggers an
atomic commit and a configChanged round through both daemons):

    for i in {1..8}; do
        kscreen-doctor output.HDMI-A-1.mode.1
        sleep 4
        kscreen-doctor output.HDMI-A-1.mode.2
        sleep 4
    done
    ps -o rss= -C kwin_wayland

(adjust output name and mode ids to your setup)

Unpatched, this grows kwin_wayland RSS by tens to hundreds of MB per batch
(observed bursts of +35 MB to +440 MB during display transitions).


SOURCE (v6.7.4, src/wayland/outputdevice_v2.cpp)
================================================

- kde_output_device_v2_bind_resource() calls sendNewMode(resource, mode) for
  each mode; sendNewMode() -> createResource() creates one new ModeResource
  per mode per bind.
- kde_output_device_v2_release() calls wl_resource_destroy() on the device
  resource only; the ModeResources created for it are orphaned.


SUGGESTED FIX
=============

Destroy the mode resources belonging to the released resource in
kde_output_device_v2_release(), using the same send_removed() +
wl_resource_destroy() pattern as ~OutputDeviceModeV2InterfacePrivate() and
updateModes(). Patch attached (verified: 8 alternating mode switches, RSS
267.5 MB -> 265.7 MB, no protocol errors from either daemon).

Note: master stopped advertising the kde-output-device-v2 globals
(commit 7e32e00c88a5122e7935827e34a6d61fefd5a5ac), but the protocol
implementation and this leak are still present there, and Plasma 6.7.x ships
it in production use.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to