free( ) pointers
- by user1043625
I'm required to use a special library to keep track of my memory leaks where malloc()= allocate( ) and free( ) = unallocate( ).
I'm trying to complete free a linked-list but it seems like the "root" value isn't being freed.
typedef struct _node {
struct _node *child;
char *command;
} Command_list;
void delete_commands(Command_list **root)
{
Command_list *temp;
while( *root != NULL ){
temp = (*root)->child;
//printf("STRING: %s\n", *root->command );
unallocate( *root );
*root = temp;
}
}
The function that's calling it
void file_processing( .... ){
Command_list *root = allocate(sizeof (Command_list));
root = NULL;
....
delete_commands( &root );
}
}
I believe that
Command_list *root = allocate(sizeof (Command_list))
isn't being properly de-allocated for some reason.
Anyone can give me some hints?
UPDATE: I found out that instead of
Command_list *root = allocate(sizeof (Command_list));
root = NULL;
this works:
Command_list *root = NULL;