From d5b5148cd58bc0b1f1a77898f3fb13a6b946df01 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Sun, 18 May 2025 12:50:20 -0700 Subject: [PATCH] Fix wrong `delete` in `MxPtrList` (#111) * Use delete[] for array types in `MxPtrList::Destroy` * Use template specialization solution --- LEGO1/lego/legoomni/include/legoroimaplist.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/LEGO1/lego/legoomni/include/legoroimaplist.h b/LEGO1/lego/legoomni/include/legoroimaplist.h index 697c2dd8..05a03b44 100644 --- a/LEGO1/lego/legoomni/include/legoroimaplist.h +++ b/LEGO1/lego/legoomni/include/legoroimaplist.h @@ -15,6 +15,23 @@ class LegoROI; // VTABLE: LEGO1 0x100d9248 // class MxPtrList +// Specialize MxPtrList for LegoROI* in order to fix Destroy. +// TODO: Change to using constexpr in MxPtrList::Destroy once C++17 standard works. +template <> +class MxPtrList : public MxList { +public: + MxPtrList(MxBool p_ownership) { SetOwnership(p_ownership); } + + static void Destroy(LegoROI** p_obj) { delete[] p_obj; } + + void SetOwnership(MxBool p_ownership) + { + MxCollection::SetDestroy( + p_ownership ? MxPtrList::Destroy : MxCollection::Destroy + ); + } +}; + // VTABLE: LEGO1 0x100d9260 // SIZE 0x18 class LegoROIMapList : public MxPtrList {