C Linked List valgrind Invalid Read of Size

南笙酒味 提交于 2019-12-02 03:10:23

One problem that I see is that in delete_map_node you free root (which might be map_list passed from find_and_free_address), but you don't actually change map_list which means that when delete_map_node returns the map_list variable points to unallocated memory. Accessing map_list afterwards leads to undefined behavior.

The simple solution to this is to assign the return value of delete_map_node to map_list:

map_list = delete_map_node(map_list, current->free_time);

Also, what happens when delete_map_node frees the node in the list that is current in the find_and_free_address function? Then current = current->next will also lead to undefined behavior.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!