-
Notifications
You must be signed in to change notification settings - Fork 909
Description
The Clang static analyzer points out that the function clear_chunk_list
accesses memory after it's been freed, in the line:
cl->head->next = NULL;
The malloc block pointed to by cl->head
has already been freed up above in the line
free(c);
The consequences of this are pretty dire. Writing into a free block is likely to corrupt heap structures (depending on the malloc implementation). It could crash immediately if the VM page was freed. Or if the block has already been handed to a malloc call on another thread, it would corrupt another program heap block.
It looks as though the fix is to change the offending line to
cl->head = NULL
although I'm not exactly sure what this function is supposed to do. If the zone is supposed to remain usable, restored to the state it was initially in after init_chunk_list
, then this isn't the right fix. Instead it should probably be freeing only the chunks that come after the first one, which would mean modifying the while loop slightly.