[graphics/digikam] core/libs/widgets/graphicsview: Fix sized deallocation mismatch in GraphicsDImgItem private container

Mikhail Hrechyn <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 6186aa52511b5cbfd92bf0664fa4bbcc0a1cb8a9 by Mikhail Hrechyn.
Committed on 22/07/2026 at 15:38.
Pushed by cgilles into branch 'master'.

Fix sized deallocation mismatch in GraphicsDImgItem private container

GraphicsDImgItemPrivate has no virtual destructor, but subclasses
create the derived DImgPreviewItemPrivate container and hand it down
to the protected GraphicsDImgItem constructor, and ~GraphicsDImgItem()
deletes it through the GraphicsDImgItemPrivate pointer. The derived
destructor is therefore never run, leaking the members of
DImgPreviewItemPrivate, and the compiler emits C++14 sized
deallocation with the size of the base class while the allocation has
the size of the subclass. Allocators enforcing the size argument, like
hardened_malloc which secureblue preloads into all Flatpak
applications, abort with "fatal allocator error: sized deallocation
mismatch (small)" when the preview item is destroyed, e.g. on
application shutdown while the map view is open.

Same pattern as the AbstractMarkerTiler::Tile fix in the previous
commit: the destructor must be virtual on the base class.

CCBUG: 522748
FIXED-IN: 9.2.0

M  +13   -1    core/libs/widgets/graphicsview/dimgitems_p.h

https://invent.kde.org/graphics/digikam/-/commit/6186aa52511b5cbfd92bf0664fa4bbcc0a1cb8a9

diff --git a/core/libs/widgets/graphicsview/dimgitems_p.h b/core/libs/widgets/graphicsview/dimgitems_p.h
index 736634d912..3674f16bff 100644
--- a/core/libs/widgets/graphicsview/dimgitems_p.h
+++ b/core/libs/widgets/graphicsview/dimgitems_p.h
@@ -79,6 +79,16 @@ public:
 
     GraphicsDImgItemPrivate() = default;
 
+    /**
+     * @note The destructor must be virtual: subclass private containers
+     * like DImgPreviewItemPrivate are deleted through a pointer to this
+     * base class in ~GraphicsDImgItem(), else the subclass destructor
+     * is skipped and C++14 sized deallocation passes the wrong size,
+     * which aborts under allocators enforcing it, like hardened_malloc.
+     * See bug #522748.
+     */
+    virtual ~GraphicsDImgItemPrivate() = default;
+
     void init(GraphicsDImgItem* const q);
 
 public:
@@ -99,7 +109,9 @@ class DIGIKAM_EXPORT DImgPreviewItem::DImgPreviewItemPrivate : public GraphicsDI
 {
 public:
 
-    DImgPreviewItemPrivate() = default;
+    DImgPreviewItemPrivate()           = default;
+    ~DImgPreviewItemPrivate() override = default;
+
     void init(DImgPreviewItem* const q);
 
 public:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.