diff --git a/src/xspice/cmpp/cmpp.h b/src/xspice/cmpp/cmpp.h index 00bbaa207..5d3865a86 100644 --- a/src/xspice/cmpp/cmpp.h +++ b/src/xspice/cmpp/cmpp.h @@ -301,6 +301,7 @@ Status_t write_ifs_c_file(const char *filename, Ifs_Table_t *ifs_table); FILE *fopen_cmpp(const char **path_p, const char *mode); +void rem_ifs_table(Ifs_Table_t *ifs_table); /* * type safe variants of the functions for char arguments diff --git a/src/xspice/cmpp/pp_ifs.c b/src/xspice/cmpp/pp_ifs.c index 00ba1dc9a..f0830b51a 100644 --- a/src/xspice/cmpp/pp_ifs.c +++ b/src/xspice/cmpp/pp_ifs.c @@ -44,6 +44,11 @@ NON-STANDARD FEATURES /* *********************************************************************** */ +static void txfree(void *ptr) +{ + if(ptr) + free(ptr); +}; /* preprocess_ifs_file @@ -65,7 +70,6 @@ void preprocess_ifs_file(void) Status_t status; /* Return status */ - /* Read the entire ifspec.ifs file and load the data into ifs_table */ status = read_ifs_file(IFSPEC_FILENAME,GET_IFS_TABLE,&ifs_table); @@ -82,7 +86,34 @@ void preprocess_ifs_file(void) if(status != OK) { exit(1); } + rem_ifs_table(&ifs_table); +} +void rem_ifs_table(Ifs_Table_t *ifs_table) +{ + int i; + /* Remove the ifs_table */ + txfree(ifs_table->name.c_fcn_name); + txfree(ifs_table->name.description); + txfree(ifs_table->name.model_name); + + for(i = 0; i < ifs_table->num_conn; i++) { + txfree(ifs_table->conn[i].name); + txfree(ifs_table->conn[i].description); + txfree(ifs_table->conn[i].default_type); + } + + for(i = 0; i < ifs_table->num_param; i++) { + txfree(ifs_table->param[i].name); + txfree(ifs_table->param[i].description); + } + for(i = 0; i < ifs_table->num_inst_var; i++) { + txfree(ifs_table->inst_var[i].name); + txfree(ifs_table->inst_var[i].description); + } + txfree(ifs_table->conn); + txfree(ifs_table->param); + txfree(ifs_table->inst_var); } diff --git a/src/xspice/cmpp/pp_lst.c b/src/xspice/cmpp/pp_lst.c index 257bb3581..5c3b3b02f 100644 --- a/src/xspice/cmpp/pp_lst.c +++ b/src/xspice/cmpp/pp_lst.c @@ -193,7 +193,16 @@ void preprocess_lst_files(void) if(status != OK) { exit(1); } - + /* remove model_info and node_info */ + if (model_info) { + if(model_info->cfunc_name) free(model_info->cfunc_name); + if(model_info->path_name) free(model_info->path_name); + if(model_info->spice_name) free(model_info->spice_name); + } + if (node_info) { + if(node_info->node_name) free(node_info->node_name); + if(node_info->path_name) free(node_info->path_name); + } } @@ -309,6 +318,9 @@ static Status_t read_modpath( *num_models = n; *model_info = model; + if(filename) + free((char*)filename); + return(OK); } @@ -424,6 +436,9 @@ static Status_t read_udnpath( *num_nodes = n; *node_info = node; + if(filename) + free((char*)filename); + return(OK); } @@ -467,14 +482,17 @@ static Status_t read_model_names( /* Transfer the names into the model_info structure */ if(status == OK) { - model_info[i].spice_name = ifs_table.name.model_name; - model_info[i].cfunc_name = ifs_table.name.c_fcn_name; + model_info[i].spice_name = strdup(ifs_table.name.model_name); + model_info[i].cfunc_name = strdup(ifs_table.name.c_fcn_name); } else { all_found = FALSE; print_error("ERROR - Problems reading %s in directory %s", IFSPEC_FILENAME, model_info[i].path_name); } + + /* Remove the ifs_table */ + rem_ifs_table(&ifs_table); } if(all_found) @@ -767,6 +785,8 @@ static Status_t write_CMextrn( /* Close the file and return */ fclose(fp); + if(filename) + free((char*)filename); return(OK); } @@ -808,6 +828,8 @@ static Status_t write_CMinfo( /* Close the file and return */ fclose(fp); + if(filename) + free((char*)filename); return(OK); } @@ -853,6 +875,8 @@ static Status_t write_UDNextrn( /* Close the file and return */ fclose(fp); + if(filename) + free((char*)filename); return(OK); } @@ -895,6 +919,8 @@ static Status_t write_UDNinfo( } /* Close the file and return */ + if(filename) + free((char*)filename); fclose(fp); return(OK); } @@ -947,6 +973,8 @@ static Status_t write_objects_inc( /* Close the file and return */ fclose(fp); + if(filename) + free((char*)filename); return(OK); } @@ -976,6 +1004,7 @@ static Status_t read_udn_type_name( /* Open the file from which the node type name will be read */ fp = fopen_cmpp(&path, "r"); + free((char*)path); if(fp == NULL) return(ERROR); diff --git a/src/xspice/cmpp/pp_mod.c b/src/xspice/cmpp/pp_mod.c index 4b2436b91..240371ed6 100644 --- a/src/xspice/cmpp/pp_mod.c +++ b/src/xspice/cmpp/pp_mod.c @@ -159,7 +159,10 @@ void preprocess_mod_file ( exit (1); } fclose (mod_yyout); - mod_yyrestart(NULL); + if(output_filename) + free((char*)output_filename); + rem_ifs_table(&ifs_table); + mod_yyrestart(NULL); } /*---------------------------------------------------------------------------*/ diff --git a/src/xspice/cmpp/read_ifs.c b/src/xspice/cmpp/read_ifs.c index 2dd038b81..9a2bb0197 100644 --- a/src/xspice/cmpp/read_ifs.c +++ b/src/xspice/cmpp/read_ifs.c @@ -150,6 +150,10 @@ static Status_t read_ifs_table( assert (ifs_table); assert (fp); + ifs_table->name.description = + ifs_table->name.c_fcn_name = + ifs_table->name.model_name = NULL; + ifs_yylineno = 1; ifs_yyin = fp; parser_just_names = (mode == GET_IFS_NAME) ? TRUE : FALSE; diff --git a/src/xspice/cmpp/writ_ifs.c b/src/xspice/cmpp/writ_ifs.c index 00ff98575..a09f61c99 100644 --- a/src/xspice/cmpp/writ_ifs.c +++ b/src/xspice/cmpp/writ_ifs.c @@ -155,7 +155,8 @@ Status_t write_ifs_c_file( /* Close the ifspec.c file and return */ int_status = fclose(fp); - + if(filename) + free((char*)filename); if(int_status == 0) return(OK); else