From 542269dffa24f3b773bca6d35a0bb2841da433c8 Mon Sep 17 00:00:00 2001
From: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
Date: Sun, 16 Aug 2026 08:53:34 -0300
Subject: Fix KviPointerList copy construction
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

KviPointerList did not define a copy constructor, so copying a list
used the compiler-generated shallow copy of its internal node pointers.

Removing elements from such a copy could therefore free nodes still
referenced by the original list, causing use-after-free in the MDI
window management code.

Add a copy constructor that creates independent list nodes through
copyFrom() while keeping auto-delete disabled for the shared pointed
objects.

This fixes the MDI window list corruption reported in #68.

Signed-off-by: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
---
 src/kvilib/core/kvi_pointerlist.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/kvilib/core/kvi_pointerlist.h b/src/kvilib/core/kvi_pointerlist.h
index 35abaa76..cdf7820c 100644
--- a/src/kvilib/core/kvi_pointerlist.h
+++ b/src/kvilib/core/kvi_pointerlist.h
@@ -1045,6 +1045,21 @@ public:
 		m_pAux	= NULL;
 	};
 
+	///
+	/// First creates an empty list
+	/// and then inserts a copy of all the item pointers present in l.
+	/// The autodelete feature is automatically disabled (take care!).
+	///
+	KviPointerList(const KviPointerList<T> &l)
+	{
+		m_bAutoDelete = false;
+		m_pHead = NULL;
+		m_pTail = NULL;
+		m_uCount = 0;
+		m_pAux	= NULL;
+		copyFrom(const_cast<KviPointerList<T> *>(&l));
+	}
+
 	///
 	/// destroys the list
 	/// if autoDelete() is set to true, all the items are deleted
-- 
cgit v1.2.3

