From a239894996717697cbaf2a396d1c81cc0818f5c5 Mon Sep 17 00:00:00 2001 From: Chip Barnaby Date: Wed, 11 Oct 2023 10:38:02 -0400 Subject: [PATCH 1/3] Looking for memory leaks --- src/CNRECS.DEF | 1 + src/pvcalc.cpp | 4 ++++ src/shading.cpp | 7 ++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/CNRECS.DEF b/src/CNRECS.DEF index fc38c0d8b..5547e2e2c 100644 --- a/src/CNRECS.DEF +++ b/src/CNRECS.DEF @@ -5348,6 +5348,7 @@ RECORD DHWSOLARCOLLECTOR "DHWSolarCollector" *RAT // input / runtime DHW solar RECORD PVARRAY "PVArray" *RAT // input / runtime photovoltaics array *prefix pv_ *excon + *exdes *ovrcopy *declare "virtual PVARRAY& CopyFrom( const record* src, int copyName=1, int dupPtrs=0);" *declare "void FixUp();" // virtual fixup after basAnc reAl diff --git a/src/pvcalc.cpp b/src/pvcalc.cpp index 7d5621f93..6d493bd29 100644 --- a/src/pvcalc.cpp +++ b/src/pvcalc.cpp @@ -26,6 +26,10 @@ PVARRAY::PVARRAY( basAnc *b, TI i, SI noZ /*=0*/) FixUp(); } // PVARRAY::PVARRAY //----------------------------------------------------------------------------- +PVARRAY::~PVARRAY() +{ +} // PVARRAY::~PVARRAY +//----------------------------------------------------------------------------- /*virtual*/ void PVARRAY::FixUp() // set parent linkage { pv_g.gx_SetParent( this); } diff --git a/src/shading.cpp b/src/shading.cpp index 9370ed82c..fc5c5e8e0 100644 --- a/src/shading.cpp +++ b/src/shading.cpp @@ -326,7 +326,9 @@ class SURFGEOMDET { friend SURFGEOM; SURFGEOMDET( SURFGEOM* pSG) : gxd_pSG( pSG) - {} + { + printf("\n SURFGEOMDET ctor %p (%p)", this, pSG); + } SURFGEOMDET( SURFGEOM* pSG, const SURFGEOMDET& sgd); bool gxd_IsEmpty() const // true iff no valid polygon { return gxd_uNorm.IsZero(); } @@ -357,6 +359,7 @@ SURFGEOMDET::SURFGEOMDET( // special copy c'tor : gxd_pSG( pSG), gxd_polygon( sgd.gxd_polygon), gxd_uNorm( sgd.gxd_uNorm), gxd_uNormT( sgd.gxd_uNormT) { + printf("\n SURFGEOMDET copy %p (%p) source = %p", this, pSG, &sgd); } // SURFGEOMDET::SURFGEOMDET //----------------------------------------------------------------------------- RC SURFGEOMDET::gxd_FillAndCheck( @@ -418,11 +421,13 @@ int SURFGEOMDET::gxd_SetupShading( // convert polygon to Penumbra format SURFGEOM::SURFGEOM() { gx_sgDet = new SURFGEOMDET( this); + printf("\nSURFGEOM c'tor %p gx_sgDet=%p", this, gx_sgDet); gx_pnIdx = -1; } // SURFGEOM::SURFGEOM //----------------------------------------------------------------------------- SURFGEOM::~SURFGEOM() { + printf("\nSURFGEOM d'tor %p gx_sgDet=%p", this, gx_sgDet); delete gx_sgDet; gx_sgDet = NULL; } // SURFGEOM::~SURFGEOM From 48966a2bb616ead1ee2419cd6aabab2e170478fd Mon Sep 17 00:00:00 2001 From: Chip Barnaby Date: Thu, 12 Oct 2023 14:15:01 -0400 Subject: [PATCH 2/3] Fix SURFGEOM memory leaks --- src/geometry.h | 7 +++++-- src/pvcalc.cpp | 2 ++ src/shading.cpp | 9 +++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/geometry.h b/src/geometry.h index b3e4c028e..5766527a5 100644 --- a/src/geometry.h +++ b/src/geometry.h @@ -207,12 +207,15 @@ class CPolygon3D { public: CPolygon3D( int n=4) - { if (n>0) + { + if (n>0) p3_vrt.reserve( n); } CPolygon3D( const CPolygon3D& p3) : p3_vrt( p3.p3_vrt) - { /* Copy( ptsAr); */ } + { + /* Copy( ptsAr); */ + } virtual ~CPolygon3D() { DeleteAll(); } void DeleteAll() { p3_vrt.clear(); } int GetSize() const { return static_cast(p3_vrt.size()); } diff --git a/src/pvcalc.cpp b/src/pvcalc.cpp index 6d493bd29..578ad6f4b 100644 --- a/src/pvcalc.cpp +++ b/src/pvcalc.cpp @@ -36,6 +36,7 @@ PVARRAY::~PVARRAY() //----------------------------------------------------------------------------- /*virtual*/ void PVARRAY::Copy( const record* pSrc, int options/*=0*/) { // bitwise copy of record + pv_g.~SURFGEOM(); // destroy SURFGEOM subobjects before bitwise overwrite record::Copy( pSrc, options); // calls FixUp() // copy SURFGEOM heap subobjects pv_g.gx_CopySubObjects(); @@ -46,6 +47,7 @@ PVARRAY::~PVARRAY() int copyName/*=1*/, int dupPtrs/*=0*/) { + pv_g.~SURFGEOM(); // destroy SURFGEOM subobjects before bitwise overwrite record::CopyFrom( src, copyName, dupPtrs); // calls FixUp() pv_g.gx_CopySubObjects(); #if defined( _DEBUG) diff --git a/src/shading.cpp b/src/shading.cpp index fc5c5e8e0..1636265be 100644 --- a/src/shading.cpp +++ b/src/shading.cpp @@ -326,10 +326,9 @@ class SURFGEOMDET { friend SURFGEOM; SURFGEOMDET( SURFGEOM* pSG) : gxd_pSG( pSG) - { - printf("\n SURFGEOMDET ctor %p (%p)", this, pSG); - } + { } SURFGEOMDET( SURFGEOM* pSG, const SURFGEOMDET& sgd); + ~SURFGEOMDET() { } bool gxd_IsEmpty() const // true iff no valid polygon { return gxd_uNorm.IsZero(); } @@ -359,7 +358,6 @@ SURFGEOMDET::SURFGEOMDET( // special copy c'tor : gxd_pSG( pSG), gxd_polygon( sgd.gxd_polygon), gxd_uNorm( sgd.gxd_uNorm), gxd_uNormT( sgd.gxd_uNormT) { - printf("\n SURFGEOMDET copy %p (%p) source = %p", this, pSG, &sgd); } // SURFGEOMDET::SURFGEOMDET //----------------------------------------------------------------------------- RC SURFGEOMDET::gxd_FillAndCheck( @@ -421,13 +419,11 @@ int SURFGEOMDET::gxd_SetupShading( // convert polygon to Penumbra format SURFGEOM::SURFGEOM() { gx_sgDet = new SURFGEOMDET( this); - printf("\nSURFGEOM c'tor %p gx_sgDet=%p", this, gx_sgDet); gx_pnIdx = -1; } // SURFGEOM::SURFGEOM //----------------------------------------------------------------------------- SURFGEOM::~SURFGEOM() { - printf("\nSURFGEOM d'tor %p gx_sgDet=%p", this, gx_sgDet); delete gx_sgDet; gx_sgDet = NULL; } // SURFGEOM::~SURFGEOM @@ -641,6 +637,7 @@ RC SHADEX::sx_Init() // init at run start //---------------------------------------------------------------------------- void SHADEX::Copy( const record* pSrc, int options/*=0*/) { // bitwise copy of record + sx_g.~SURFGEOM(); // destroy SURFGEOM subobjects before bitwise overwrite record::Copy( pSrc, options); // calls FixUp() // copy SURFGEOM heap subobjects sx_g.gx_CopySubObjects(); From 9169c6573de1963277606883b8ad2287e12daa6e Mon Sep 17 00:00:00 2001 From: Chip Barnaby Date: Tue, 6 Feb 2024 13:37:00 -0500 Subject: [PATCH 3/3] Update submodules --- vendor/HPWHsim | 2 +- vendor/btwxt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/HPWHsim b/vendor/HPWHsim index d20541324..b3e2507c0 160000 --- a/vendor/HPWHsim +++ b/vendor/HPWHsim @@ -1 +1 @@ -Subproject commit d2054132479a920d651a77a733e53de2a24e634b +Subproject commit b3e2507c084c8914bc8ee4ce85cb4856b5bc472b diff --git a/vendor/btwxt b/vendor/btwxt index 692bcce95..2a5926e96 160000 --- a/vendor/btwxt +++ b/vendor/btwxt @@ -1 +1 @@ -Subproject commit 692bcce95f501c52ff627353d8fb90c9e7fbd2ea +Subproject commit 2a5926e96b594bafbcaa7640a9cabd40b5ae043d