add callback function to delete the memory

allocated in the code model
This commit is contained in:
Holger Vogt 2018-08-10 23:35:33 +02:00
parent 9d36a2e326
commit d26d1b96ec
2 changed files with 52 additions and 9 deletions

View File

@ -29,6 +29,7 @@ AUTHORS
MODIFICATIONS
10 Aug 2018 Holger Vogt
SUMMARY
@ -291,6 +292,26 @@ cnv_get_spice_value(char *str, /* IN - The value text e.g. 1.2K */
return OK;
}
static void
cm_table2D_callback(ARGS, Mif_Callback_Reason_t reason)
{
switch (reason) {
case MIF_CB_DESTROY: {
int i;
Local_Data_t *loc = STATIC_VAR (locdata);
if (loc->state->fp)
fclose(loc->state->fp);
free(loc->state);
for (i = 0; i < loc->iy; i++)
free(loc->table[i]);
free(loc->table);
free(loc);
break;
}
}
}
/*==============================================================================
@ -380,6 +401,8 @@ cm_table2D(ARGS) /* structure holding parms, inputs, outputs, etc. */
size_t lTotalChars; /* Total characters read */
int interporder; /* order of interpolation for eno */
CALLBACK = cm_table2D_callback;
/* allocate static storage for *loc */
STATIC_VAR (locdata) = calloc(1, sizeof(Local_Data_t));
loc = STATIC_VAR (locdata);
@ -594,10 +617,7 @@ cm_table2D(ARGS) /* structure holding parms, inputs, outputs, etc. */
/* fill table data into eno2 structure */
sf_eno2_set (loc->newtable, table_data /* data [n2][n1] */);
/* free all the emory allocated */
// for (i = 0; i < iy; i++)
// free(table_data[i]);
// free(table_data);
/* free the file memory allocated */
free(cFile);
free(cThisLine);
} /* end of initialization "if (INIT == 1)" */

View File

@ -29,6 +29,7 @@ AUTHORS
MODIFICATIONS
10 Aug 2018 Holger Vogt
SUMMARY
@ -297,6 +298,29 @@ cnv_get_spice_value(char *str, /* IN - The value text e.g. 1.2K */
return OK;
}
static void
cm_table3D_callback(ARGS, Mif_Callback_Reason_t reason)
{
switch (reason) {
case MIF_CB_DESTROY: {
int i, j;
Local_Data_t *loc = STATIC_VAR (locdata);
if (loc->state->fp)
fclose(loc->state->fp);
free(loc->state);
for (i = 0; i < loc->iz; i++) {
for (j = 0; j < loc->iy; j++)
free(loc->table[i][j]);
free(loc->table[i]);
}
free(loc->table);
free(loc);
break;
}
}
}
/*==============================================================================
@ -312,7 +336,7 @@ MODIFICATIONS
SUMMARY
This function implements 2D table code model.
This function implements 3D table code model.
INTERFACES
@ -389,6 +413,8 @@ cm_table3D(ARGS) /* structure holding parms, inputs, outputs, etc. */
int lTableCount; /* Number of tables */
int interporder; /* order of interpolation for eno */
CALLBACK = cm_table3D_callback;
/* allocate static storage for *loc */
STATIC_VAR (locdata) = calloc (1, sizeof(Local_Data_t));
loc = STATIC_VAR (locdata);
@ -631,10 +657,7 @@ cm_table3D(ARGS) /* structure holding parms, inputs, outputs, etc. */
sf_eno3_set(loc->newtable, table_data /* data [n3][n2][n1] */);
/* free all the emory allocated */
// for (i = 0; i < iy; i++)
// free(table_data[i]);
// free(table_data);
/* free file memory allocated */
free(cFile);
free(cThisLine);
} /* end of initialization "if (INIT == 1)" */