From 131e40dab98af14abb607ffa831f9cd834db12ce Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sat, 28 Jan 2012 10:35:04 +0000 Subject: [PATCH] prevent crash upon 'reset' (MS Windows only) --- ChangeLog | 2 ++ src/xspice/mif/mifdelete.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3b1a0ba93..45e7fbd34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2012-01-28 Holger Vogt * configure.ac, compile_min.sh: prepare for release 24 + * mifdelete.c: prevent crash upon 'reset', if codemodel is an array + FIXME: leads to small memory leak 2012-01-27 Holger Vogt * NEWS, INSTALL, tests\bin\ngspice.pm, /visualc/include/ngspice/config.h: diff --git a/src/xspice/mif/mifdelete.c b/src/xspice/mif/mifdelete.c index 0154c6131..80bd99b10 100755 --- a/src/xspice/mif/mifdelete.c +++ b/src/xspice/mif/mifdelete.c @@ -48,7 +48,7 @@ NON-STANDARD FEATURES #include "ngspice/suffix.h" - +#include "ngspice/devdefs.h" /* MIFdelete @@ -172,7 +172,15 @@ MIFdelete( num_inst_var = here->num_inst_var; for(i = 0; i < num_inst_var; i++) { if(here->inst_var[i]->element != NULL) { - FREE(here->inst_var[i]->element); + /* Do not delete inst_var[i]->element if MS Windows and is_array==1. + Memory is then allocated in the code model dll, and it cannot be + guaranteed that it can be freed safely here! A small memory leak is created. + FIXME + Finally one has to free the memory in the same module where allocated. */ +#if defined(_MSC_VER) || defined(__MINGW32__) + if(!DEVices[here->MIFmodPtr->MIFmodType]->DEVpublic.inst_var[i].is_array) +#endif + FREE(here->inst_var[i]->element); } FREE(here->inst_var[i]); }