简体   繁体   English

释放链表 C 中的节点 [关闭]

[英]Freeing Node in linked list C [closed]

enter image description here在此处输入图像描述

I wonder why I cannot free node b and c我想知道为什么我不能释放节点 b 和 c

Also, I have repeatedly freed b after the while loop and lines after while loop do not work as well.另外,我在 while 循环之后反复释放 b ,而 while 循环之后的行也不能正常工作。

What is the problem here?这里有什么问题?

The allocated memory is actually being freed.分配的 memory 实际上正在被释放。 However the variable still contains the memory address.但是该变量仍然包含 memory 地址。 Accessing that address after the memory has been freed is undefined behavior.在 memory 被释放后访问该地址是未定义的行为。 In this case it's showing you what was there, however it could just as easily cause a crash.在这种情况下,它会向您展示那里有什么,但它也很容易导致崩溃。 Later when you free(b) you are definitely corrupting your heap because that memory has already been freed in your while loop.稍后当你free(b)时,你肯定会破坏你的堆,因为 memory 已经在你的 while 循环中被释放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM