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

Allen Winter <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REPORTED                    |RESOLVED
         Resolution|---                         |FIXED
      Latest Commit|                            |https://invent.kde.org/pim/
                   |                            |kdepim-runtime/-/commit/222
                   |                            |3be6dfadcfff0e000538f6c9e5f
                   |                            |15e040077d

--- Comment #1 from Allen Winter <[email protected]> ---
Git commit 2223be6dfadcfff0e000538f6c9e5f15e040077d by Allen Winter, on behalf
of Sergey Kostyuchenko.
Committed on 12/11/2026 at 14:10.
Pushed by winterz into branch 'master'.

Destroy the EWS subscription manager before the other resource members

`EwsResource` now tears down its subscription manager before any other member
is
destroyed. Nothing else changes.

**What and why**

`EwsResource` declares `QScopedPointer<EwsSubscriptionManager> mSubManager`
(`resources/ews/ewsresource.h:169`) before `QScopedPointer<EwsSettings>
mSettings`
(`resources/ews/ewsresource.h:181` before this change, 183 after). Members are
destroyed in
reverse declaration order, so the settings are freed first and the subscription
manager
second, and `~EwsSubscriptionManager()` calls `cancelSubscription()`, which
dereferences
`mSettings` (a raw `EwsSettings *`, not a `QPointer`) to read
`eventSubscriptionId()`,
clear it and call `save()`.

Chain: `mSettings` is destroyed before `mSubManager` ->
`~EwsSubscriptionManager()` reads and
saves `mSettings` -> use-after-free when the agent stops.

Only `doSetOnline(false)` (`resources/ews/ewsresource.cpp:1243-1249`) and
`reloadConfig()`
(`resources/ews/ewsresource.cpp:436-442`) used to reset the manager before
teardown, and
Akonadi's `AgentBase::quit()` does not go offline, so a normal agent stop
reaches the
destructor with the manager still alive.

**How**

`~EwsResource()` (`resources/ews/ewsresource.cpp:131`) now has a real body that
calls
`mSubManager.reset()` before any member is destroyed, plus a comment at the
declaration
documenting the dependency on `mSettings`. The declaration order is
deliberately left
alone: with the explicit reset it no longer matters, and reordering would only
widen the
diff.

**Verification**

- `prek run --files resources/ews/ewsresource.cpp resources/ews/ewsresource.h`:
all hooks
  pass, including clang-format with the project's own configuration and
codespell.
- No full build locally: the machine where this was written has no dev output
for kdav
  (`KF6DAVConfig.cmake` is missing), so kdepim-runtime cannot be configured
there. CI is
  the first real build of this change.
- No unit test: constructing an `EwsResource` needs a live Akonadi/D-Bus
session and an
  agent config, while the existing EWS unit tests only build isolated jobs.

M  +7    -1    resources/ews/ewsresource.cpp
M  +2    -0    resources/ews/ewsresource.h

https://invent.kde.org/pim/kdepim-runtime/-/commit/2223be6dfadcfff0e000538f6c9e5f15e040077d

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

Reply via email to