C++ 什么会导致“损坏的双链表”错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1819982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What can cause "corrupted double-linked list" error?
提问by hanno
I am having problems with a fairly complex code. I wasn't able to produce a short snippet that reproduces the error, so I'll try to explain the problem in words.
我在使用相当复杂的代码时遇到问题。我无法生成重现错误的简短片段,因此我将尝试用文字解释问题。
The code crashes randomly with the error
代码随机崩溃并出现错误
*** glibc detected *** gravtree: corrupted double-linked list: 0x000000001aa0fc50 ***
Debugging showed that it comes from the line where the codes frees an object. There seems to be nothing wrong with the object. It exists, and I can access it's data at the time the error occurs. The object's destructor is trivial and doesn't do anything.
调试表明它来自代码释放对象的行。对象似乎没有任何问题。它存在,我可以在错误发生时访问它的数据。对象的析构函数是微不足道的,不做任何事情。
So, I'm kind of stuck. In what kind of circumstances do you expect 'free' to fail?
所以,我有点卡住了。在什么样的情况下,你预计“免费”会失败?
采纳答案by Warren Young
回答by Chris Benesch
As Warren said, Valgrind is usually the best way to find it. The doubly linked list is a base of usually network or binary data handlers, ie in QT QByteArray
or QTcpSocket
. I had the same thing today and it was because I had invalidated an object by deleting it off a map but had previously obtained pointers to data inside of it. It worked sometimes, sometimes not. The higher the load on the system the more likely it would crash.
正如沃伦所说,Valgrind 通常是找到它的最佳方式。双向链表通常是网络或二进制数据处理程序的基础,即在 QTQByteArray
或QTcpSocket
. 我今天遇到了同样的事情,这是因为我通过从地图上删除一个对象来使它无效,但之前已经获得了指向其中数据的指针。它有时起作用,有时不起作用。系统负载越高,崩溃的可能性就越大。