Skip to content

Commit 2aff32d

Browse files
committed
fix: properly free Registert structs from heap
1 parent 49cbd8b commit 2aff32d

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/estruturas.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ void free_module(Module** mod)
6060
if ( (*mod)->list_param.itens )
6161
free( (*mod)->list_param.itens );
6262

63-
if ( (*mod)->list_register.itens )
64-
free( (*mod)->list_register.itens );
63+
delete_list_register( &((*mod)->list_register) );
6564

6665
if ( (*mod)->sinais_input )
6766
free( (*mod)->sinais_input );
@@ -171,6 +170,25 @@ void delete_list_component(ListComponent** ppl)
171170
*ppl = NULL;
172171
}
173172

173+
void delete_list_register(ListRegister* list_reg)
174+
{
175+
if ( !list_reg || !list_reg->itens )
176+
return;
177+
178+
int i;
179+
180+
for ( i = 0; i < list_reg->total; i++ )
181+
{
182+
if ( list_reg->itens[i] ) {
183+
free( list_reg->itens[i] );
184+
}
185+
}
186+
187+
free( list_reg->itens );
188+
list_reg->itens = NULL;
189+
list_reg->total = 0;
190+
}
191+
174192
void insert_component(ListComponent* ls, Component* cp)
175193
{
176194
ls->tamanho++;

src/estruturas.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ ListComponent* new_list_component_of_size(unsigned int size);
280280
*/
281281
void delete_list_component(ListComponent** ppl);
282282

283+
/** @brief Libera completamente uma lista de registradores da memória.
284+
* @param list_reg Ponteiro para a struct ListRegister a ser liberada.
285+
*/
286+
void delete_list_register(ListRegister* list_reg);
287+
283288
/** @brief Insere o componente na lista de componentes.
284289
* @param ls Ponteiro para a lista de componentes.
285290
* @param cp Ponteiro para o componente a ser inserido.

0 commit comments

Comments
 (0)