xspice/icm/analog/file_source/cfunc.mod, use CALLBACK

to free() locally allocated memory and fclose() a local filestream
This commit is contained in:
rlar 2017-03-04 11:17:37 +01:00
parent 58874cc65e
commit 926ba4baaf
1 changed files with 19 additions and 0 deletions

View File

@ -138,6 +138,23 @@ NON-STANDARD FEATURES
/*=== CM_FILESOURCE ROUTINE ===*/
static void
cm_filesource_callback(ARGS, Mif_Callback_Reason_t reason)
{
switch (reason) {
case MIF_CB_DESTROY: {
Local_Data_t *loc = STATIC_VAR (locdata);
fclose(loc->state->fp);
free(loc->state);
free(loc->amplinterval);
free(loc->timeinterval);
free(loc);
break;
}
}
}
void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc. */
{
int size = PORT_SIZE(out);
@ -154,6 +171,8 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
int i;
CALLBACK = cm_filesource_callback;
/*** allocate static storage for *loc ***/
STATIC_VAR (locdata) = calloc (1 , sizeof ( Local_Data_t ));
loc = STATIC_VAR (locdata);