free( ) pointers
Posted
by
user1043625
on Stack Overflow
See other posts from Stack Overflow
or by user1043625
Published on 2012-10-01T09:31:21Z
Indexed on
2012/10/01
9:37 UTC
Read the original article
Hit count: 139
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;
© Stack Overflow or respective owner