From 6ae9c221ab61a87ca47fa36771cac0886d052304 Mon Sep 17 00:00:00 2001
From: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
Date: Fri, 18 Sep 2026 07:00:10 -0300
Subject: KMail: complete POP mail check progress on account removal
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Complete any remaining POP mail check progress item when the account is destroyed.

The active TDEIO job is already killed by PopAccount's destructor, but a quiet
job cancellation bypasses the normal completion path that removes the progress
item from ProgressManager.

Clear the guarded pointer before completing the item, matching the existing
normal completion pattern and avoiding reentrant access during teardown.

Signed-off-by: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
---
 kmail/popaccount.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kmail/popaccount.cpp b/kmail/popaccount.cpp
index 12af2bdc..e485e446 100644
--- a/kmail/popaccount.cpp
+++ b/kmail/popaccount.cpp
@@ -92,6 +92,13 @@ PopAccount::~PopAccount()
     processRemainingQueuedMessages();
     saveUidList();
   }
+  if ( mMailCheckProgressItem ) {
+    // set mMailCheckProgressItem = 0 before calling setComplete() to prevent
+    // a race condition
+    ProgressItem *savedMailCheckProgressItem = mMailCheckProgressItem;
+    mMailCheckProgressItem = 0;
+    savedMailCheckProgressItem->setComplete(); // that will delete it
+  }
 }
 
 
-- 
cgit v1.2.3

