From d864bd750c2c7234c6690098782a8ed9f7363f6c Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 7 Dec 2019 14:53:08 +0100 Subject: [PATCH] plug a memory leak by CALLBACK, deleting locally malloced memory --- src/xspice/icm/analog/pwl/cfunc.mod | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/xspice/icm/analog/pwl/cfunc.mod b/src/xspice/icm/analog/pwl/cfunc.mod index a211be524..9a2ee5d99 100644 --- a/src/xspice/icm/analog/pwl/cfunc.mod +++ b/src/xspice/icm/analog/pwl/cfunc.mod @@ -224,6 +224,25 @@ NON-STANDARD FEATURES ==============================================================================*/ +static void +cm_pwl_callback(ARGS, Mif_Callback_Reason_t reason) +{ + switch (reason) { + case MIF_CB_DESTROY: { + double *last_x_value = STATIC_VAR (last_x_value); + double *x = STATIC_VAR (x); + double *y = STATIC_VAR (y); + free(last_x_value); + free(x); + free(y); + STATIC_VAR (last_x_value) = NULL; + STATIC_VAR (x) = NULL; + STATIC_VAR (y) = NULL; + break; + } + } +} + /*=== CM_PWL ROUTINE ================*/ void cm_pwl(ARGS) /* structure holding parms, @@ -250,7 +269,9 @@ void cm_pwl(ARGS) /* structure holding parms, double test; /* temp storage variable for limit testing */ Mif_Complex_t ac_gain; - + + CALLBACK = cm_pwl_callback; + char *allocation_error="\n***ERROR***\nPWL: Allocation calloc failed!\n"; char *limit_error="\n***ERROR***\nPWL: Violation of 50% rule in breakpoints!\n";