Fix XSPICE memory leaks found by valgrind.
This commit is contained in:
parent
ac8f8ad65d
commit
dbf4c16bc0
|
|
@ -30,6 +30,14 @@ EVTdest(Evt_Ckt_Data_t *evt)
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void free_events(Evt_Inst_Event_t *event)
|
||||||
|
{
|
||||||
|
while (event) {
|
||||||
|
Evt_Inst_Event_t *next = event->next;
|
||||||
|
tfree(event);
|
||||||
|
event = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Evt_Queue_destroy(Evt_Ckt_Data_t *evt, Evt_Queue_t *queue)
|
Evt_Queue_destroy(Evt_Ckt_Data_t *evt, Evt_Queue_t *queue)
|
||||||
|
|
@ -40,15 +48,11 @@ Evt_Queue_destroy(Evt_Ckt_Data_t *evt, Evt_Queue_t *queue)
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* instance queue */
|
|
||||||
for (i = 0; i < evt->counts.num_insts; i++) {
|
for (i = 0; i < evt->counts.num_insts; i++) {
|
||||||
Evt_Inst_Event_t *event = inst_queue->head[i];
|
free_events(inst_queue->head[i]);
|
||||||
while (event) {
|
free_events(inst_queue->free[i]);
|
||||||
Evt_Inst_Event_t *next = event->next;
|
|
||||||
tfree(event);
|
|
||||||
event = next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tfree(inst_queue->head);
|
tfree(inst_queue->head);
|
||||||
tfree(inst_queue->current);
|
tfree(inst_queue->current);
|
||||||
tfree(inst_queue->last_step);
|
tfree(inst_queue->last_step);
|
||||||
|
|
@ -114,6 +118,16 @@ Evt_Data_destroy(Evt_Ckt_Data_t *evt, Evt_Data_t *data)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static void free_state(Evt_State_t *state)
|
||||||
|
{
|
||||||
|
while (state) {
|
||||||
|
Evt_State_t *next = state->next;
|
||||||
|
tfree(state->block);
|
||||||
|
tfree(state);
|
||||||
|
state = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Evt_State_Data_destroy(Evt_Ckt_Data_t *evt, Evt_State_Data_t *state_data)
|
Evt_State_Data_destroy(Evt_Ckt_Data_t *evt, Evt_State_Data_t *state_data)
|
||||||
{
|
{
|
||||||
|
|
@ -123,13 +137,8 @@ Evt_State_Data_destroy(Evt_Ckt_Data_t *evt, Evt_State_Data_t *state_data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < evt->counts.num_insts; i++) {
|
for (i = 0; i < evt->counts.num_insts; i++) {
|
||||||
Evt_State_t *state = state_data->head[i];
|
free_state(state_data->head[i]);
|
||||||
while (state) {
|
free_state(state_data->free[i]);
|
||||||
Evt_State_t *next = state->next;
|
|
||||||
tfree(state->block);
|
|
||||||
tfree(state);
|
|
||||||
state = next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tfree(state_data->head);
|
tfree(state_data->head);
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ void EVTqueue_inst(
|
||||||
Evt_Inst_Event_t *new_event;
|
Evt_Inst_Event_t *new_event;
|
||||||
Evt_Inst_Event_t *next;
|
Evt_Inst_Event_t *next;
|
||||||
|
|
||||||
Mif_Boolean_t splice, malloced = FALSE;
|
Mif_Boolean_t splice;
|
||||||
|
|
||||||
|
|
||||||
/* Get pointers for fast access */
|
/* Get pointers for fast access */
|
||||||
|
|
@ -196,26 +196,12 @@ void EVTqueue_inst(
|
||||||
(event_time < inst_queue->next_time))
|
(event_time < inst_queue->next_time))
|
||||||
inst_queue->next_time = event_time;
|
inst_queue->next_time = event_time;
|
||||||
|
|
||||||
/* Create a new event or get one from the free list and copy in data */
|
|
||||||
if(inst_queue->free[inst_index]) {
|
|
||||||
new_event = inst_queue->free[inst_index];
|
|
||||||
inst_queue->free[inst_index] = new_event->next;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
new_event = TMALLOC(Evt_Inst_Event_t, 1);
|
|
||||||
malloced = TRUE;
|
|
||||||
}
|
|
||||||
new_event->event_time = event_time;
|
|
||||||
new_event->posted_time = posted_time;
|
|
||||||
|
|
||||||
/* Find location at which to insert event */
|
/* Find location at which to insert event */
|
||||||
splice = MIF_FALSE;
|
splice = MIF_FALSE;
|
||||||
here = inst_queue->current[inst_index];
|
here = inst_queue->current[inst_index];
|
||||||
while(*here) {
|
while(*here) {
|
||||||
/* If there's an event with the same time, don't duplicate it */
|
/* If there's an event with the same time, don't duplicate it */
|
||||||
if(event_time == (*here)->event_time) {
|
if(event_time == (*here)->event_time) {
|
||||||
if(malloced)
|
|
||||||
tfree(new_event);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(event_time < (*here)->event_time) {
|
else if(event_time < (*here)->event_time) {
|
||||||
|
|
@ -225,6 +211,17 @@ void EVTqueue_inst(
|
||||||
here = &((*here)->next);
|
here = &((*here)->next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create a new event or get one from the free list and copy in data */
|
||||||
|
if(inst_queue->free[inst_index]) {
|
||||||
|
new_event = inst_queue->free[inst_index];
|
||||||
|
inst_queue->free[inst_index] = new_event->next;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new_event = TMALLOC(Evt_Inst_Event_t, 1);
|
||||||
|
}
|
||||||
|
new_event->event_time = event_time;
|
||||||
|
new_event->posted_time = posted_time;
|
||||||
|
|
||||||
/* If needs to be spliced into middle of existing list */
|
/* If needs to be spliced into middle of existing list */
|
||||||
if(splice) {
|
if(splice) {
|
||||||
/* splice it in */
|
/* splice it in */
|
||||||
|
|
|
||||||
|
|
@ -1410,6 +1410,7 @@ static int cm_read_state_file(FILE *state_file,State_Table_t *states)
|
||||||
type = CNV_STRING_TOK;
|
type = CNV_STRING_TOK;
|
||||||
while ( type != CNV_NO_TOK ) {
|
while ( type != CNV_NO_TOK ) {
|
||||||
token = CNVget_token(&s, &type);
|
token = CNVget_token(&s, &type);
|
||||||
|
free(token);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
num_tokens = (j-1);
|
num_tokens = (j-1);
|
||||||
|
|
@ -1815,7 +1816,10 @@ void cm_d_state(ARGS)
|
||||||
states->num_outputs = PORT_SIZE(out);
|
states->num_outputs = PORT_SIZE(out);
|
||||||
|
|
||||||
|
|
||||||
/* assign storage for arrays to pointers in states table */
|
/* Assign storage for arrays to pointers in states table.
|
||||||
|
* This needs to be fixed as the memory can not be recovered.
|
||||||
|
* The *states data is deleted before any deletion callback is made.
|
||||||
|
*/
|
||||||
states->state = (int *) calloc((size_t) (states->depth + 1), sizeof(int));
|
states->state = (int *) calloc((size_t) (states->depth + 1), sizeof(int));
|
||||||
states->bits = (short *) calloc((size_t) (states->num_outputs * states->depth / 4 + 1), sizeof(short));
|
states->bits = (short *) calloc((size_t) (states->num_outputs * states->depth / 4 + 1), sizeof(short));
|
||||||
states->inputs = (short *) calloc((size_t) (states->num_inputs * states->depth / 8 + 1), sizeof(short));
|
states->inputs = (short *) calloc((size_t) (states->num_inputs * states->depth / 8 + 1), sizeof(short));
|
||||||
|
|
|
||||||
|
|
@ -524,6 +524,7 @@ static Table2_Data_t *init_local_data(const char *filename, int order)
|
||||||
while (token) {
|
while (token) {
|
||||||
if (i == ix) {
|
if (i == ix) {
|
||||||
cm_message_printf("Too many numbers in x row.");
|
cm_message_printf("Too many numbers in x row.");
|
||||||
|
free(token);
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
goto EXITPOINT;
|
goto EXITPOINT;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -705,6 +705,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
cm_message_printf("Too many numbers in y row "
|
cm_message_printf("Too many numbers in y row "
|
||||||
"no. %d of table %d.",
|
"no. %d of table %d.",
|
||||||
lLineCount, lTableCount);
|
lLineCount, lTableCount);
|
||||||
|
free(token);
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
goto EXITPOINT;
|
goto EXITPOINT;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue