From 6ba4a6e6c67d51b3900b1e05df1ee821107831b5 Mon Sep 17 00:00:00 2001 From: Monty Montgomery Date: Sun, 15 May 2022 00:36:17 -0400 Subject: [PATCH] Correct deletion of non-allocated memory in ngarray A default-constructed (or just empty) ngarray will have 'ownmem' set despite not having an allocated data array. Destructor would then trigger an abort. --- libsrc/general/ngarray.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libsrc/general/ngarray.hpp b/libsrc/general/ngarray.hpp index 05639aea..1b16c46b 100644 --- a/libsrc/general/ngarray.hpp +++ b/libsrc/general/ngarray.hpp @@ -295,8 +295,9 @@ namespace netgen /// if responsible, deletes memory ~NgArray() { - if (ownmem) - delete [] data; + if (data) + if (ownmem) + delete [] data; } /// Change logical size. If necessary, do reallocation. Keeps contents. @@ -374,8 +375,9 @@ namespace netgen /// Deallocate memory void DeleteAll () { - if (ownmem) - delete [] data; + if (data) + if (ownmem) + delete [] data; data = 0; size = allocsize = 0; }