From 7bf43cd1931232cbf5704f9dd284265fa85ee3d3 Mon Sep 17 00:00:00 2001 From: danperisse-hue Date: Fri, 27 Nov 2026 14:03:01 -0300 Subject: [PATCH] Fix two new/delete mismatches AddressSanitizer stops on On Linux under AddressSanitizer, the first two map loads stopped on two mismatches, both older than openPR06: - idPVS::Init allocates connectedAreas, areaQueue, areaPVS and each currentPVS[i].pvs with new[], and idPVS::Shutdown freed them with delete. They are now freed with delete[]. - idAnimManager::GetAnim creates HUMANHEAD's hhMD5Anim, and FlushUnusedAnims, Shutdown and the failed-load path delete it through an idMD5Anim pointer, whose destructor was not virtual. The destructor is now virtual. idMD5Anim already had virtual functions, so this adds no vptr. Neither does visible harm with glibc today, but both are undefined behaviour, and they kept ASan runs from getting past the first two map loads without alloc_dealloc_mismatch=0 and new_delete_type_mismatch=0. --- src/game/Pvs.cpp | 8 ++++---- src/game/anim/Anim.h | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/game/Pvs.cpp b/src/game/Pvs.cpp index 9d1f36e95..9bd19136c 100644 --- a/src/game/Pvs.cpp +++ b/src/game/Pvs.cpp @@ -973,20 +973,20 @@ idPVS::Shutdown */ void idPVS::Shutdown( void ) { if ( connectedAreas ) { - delete connectedAreas; + delete[] connectedAreas; connectedAreas = NULL; } if ( areaQueue ) { - delete areaQueue; + delete[] areaQueue; areaQueue = NULL; } if ( areaPVS ) { - delete areaPVS; + delete[] areaPVS; areaPVS = NULL; } if ( currentPVS ) { for ( int i = 0; i < MAX_CURRENT_PVS; i++ ) { - delete currentPVS[i].pvs; + delete[] currentPVS[i].pvs; currentPVS[i].pvs = NULL; } } diff --git a/src/game/anim/Anim.h b/src/game/anim/Anim.h index 2ac81534c..474ef214a 100644 --- a/src/game/anim/Anim.h +++ b/src/game/anim/Anim.h @@ -245,7 +245,9 @@ class idMD5Anim { public: idMD5Anim(); - ~idMD5Anim(); + // HUMANHEAD's hhMD5Anim derives from this, and idAnimManager deletes + // it through an idMD5Anim pointer. + virtual ~idMD5Anim(); void Free( void ); bool Reload( void );