diff --git a/src/spicelib/devices/cpl/Makefile.am b/src/spicelib/devices/cpl/Makefile.am
index a3da8a735..9cbd00a18 100644
--- a/src/spicelib/devices/cpl/Makefile.am
+++ b/src/spicelib/devices/cpl/Makefile.am
@@ -14,6 +14,9 @@ libcpl_la_SOURCES = \
cplload.c \
cplmpar.c \
cplsetup.c \
+ cplhash.c \
+ cplmdel.c \
+ cpldelete.c \
cplinit.c
AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/src/include
diff --git a/src/spicelib/devices/cpl/cpldelete.c b/src/spicelib/devices/cpl/cpldelete.c
new file mode 100644
index 000000000..5159a7d70
--- /dev/null
+++ b/src/spicelib/devices/cpl/cpldelete.c
@@ -0,0 +1,21 @@
+/**********
+Copyright 2021 The ngspice team All rights
+reserved.
+Author: 2021 Holger Vogt
+3-clause BSD license
+**********/
+
+#include "ngspice/ngspice.h"
+#include "cpldefs.h"
+#include "ngspice/sperror.h"
+#include "ngspice/suffix.h"
+#include "cplhash.h"
+
+int
+CPLDelete(GENinstance *gen_inst)
+{
+ NG_IGNORE(gen_inst);
+
+// mem_delete();
+ return OK;
+}
diff --git a/src/spicelib/devices/cpl/cplext.h b/src/spicelib/devices/cpl/cplext.h
index 2225084aa..4c28a93a6 100644
--- a/src/spicelib/devices/cpl/cplext.h
+++ b/src/spicelib/devices/cpl/cplext.h
@@ -11,3 +11,5 @@ extern int CPLmParam(int,IFvalue*, GENmodel*);
extern int CPLparam(int,IFvalue*, GENinstance*, IFvalue*);
extern int CPLsetup(SMPmatrix*, GENmodel*, CKTcircuit*, int*);
extern int CPLunsetup(GENmodel*, CKTcircuit*);
+extern int CPLmDelete(GENmodel*);
+extern int CPLDelete(GENinstance*);
diff --git a/src/spicelib/devices/cpl/cplinit.c b/src/spicelib/devices/cpl/cplinit.c
index b6a9aff7c..4386a939b 100644
--- a/src/spicelib/devices/cpl/cplinit.c
+++ b/src/spicelib/devices/cpl/cplinit.c
@@ -43,8 +43,8 @@ SPICEdev CPLinfo = {
.DEVacLoad = NULL,
.DEVaccept = NULL,
.DEVdestroy = NULL,
- .DEVmodDelete = NULL,
- .DEVdelete = NULL,
+ .DEVmodDelete = CPLmDelete,
+ .DEVdelete = CPLDelete,
.DEVsetic = NULL,
.DEVask = CPLask,
.DEVmodAsk = CPLmAsk,
diff --git a/src/spicelib/devices/cpl/cplmdel.c b/src/spicelib/devices/cpl/cplmdel.c
new file mode 100644
index 000000000..5f493ec55
--- /dev/null
+++ b/src/spicelib/devices/cpl/cplmdel.c
@@ -0,0 +1,24 @@
+/**********
+Copyright 2021 The ngspice team All rights
+reserved.
+Author: 2021 Holger Vogt
+3-clause BSD license
+**********/
+
+#include "ngspice/ngspice.h"
+#include "cpldefs.h"
+#include "ngspice/sperror.h"
+#include "ngspice/suffix.h"
+
+
+int
+CPLmDelete(GENmodel *gen_model)
+{
+ CPLmodel *model = (CPLmodel *)gen_model;
+
+ FREE(model->Rm);
+ FREE(model->Lm);
+ FREE(model->Gm);
+ FREE(model->Cm);
+ return OK;
+}
diff --git a/src/spicelib/devices/cpl/cplmpar.c b/src/spicelib/devices/cpl/cplmpar.c
index 693bd5a7d..eea37b6bb 100644
--- a/src/spicelib/devices/cpl/cplmpar.c
+++ b/src/spicelib/devices/cpl/cplmpar.c
@@ -19,12 +19,10 @@ static void copy_coeffs(double **dst, IFvalue *value)
int n = value->v.numValue;
if (*dst) {
- memdeleted(*dst);
tfree(*dst);
}
*dst = TMALLOC(double, n);
- memsaved(*dst);
memcpy(*dst, value->v.vec.rVec, (size_t) n * sizeof(double));
}
diff --git a/src/spicelib/devices/cpl/cplsetup.c b/src/spicelib/devices/cpl/cplsetup.c
index 82e06bea7..7584269f7 100644
--- a/src/spicelib/devices/cpl/cplsetup.c
+++ b/src/spicelib/devices/cpl/cplsetup.c
@@ -374,7 +374,7 @@ CPLunsetup(GENmodel* inModel, CKTcircuit* ckt)
here->CPLibr2Given = 0;
}
}
- mem_delete();
+// mem_delete();
return OK;
}
@@ -1408,6 +1408,7 @@ generate_out(int dim, int deg_o)
}
}
p = SIV[i][j].Poly = (double*)calloc(7, sizeof(double));
+ memsaved(p);
p[0] = c1;
p[1] = c2;
p[2] = c3;
@@ -1540,6 +1541,7 @@ static void matrix_p_mult(
for (k = 0; k < dim; k++) {
p = X[i][j].Poly[k] =
(double*)calloc((size_t)(deg_o + 1), sizeof(double));
+ memsaved(p);
mult_p(A_in[i][k], T[k][j], p, deg, deg_o, deg_o);
t1 = X[i][j].C_0[k] = p[0];
if (t1 != 0.0) {
diff --git a/visualc/vngspice.vcxproj b/visualc/vngspice.vcxproj
index f6d2c27fb..9c37b349e 100644
--- a/visualc/vngspice.vcxproj
+++ b/visualc/vngspice.vcxproj
@@ -2053,10 +2053,12 @@
+
+