multithreading *** 检测到 glibc *** 双重释放或损坏(fasttop):

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2197547/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:06:49  来源:igfitidea点击:

*** glibc detected *** double free or corruption (fasttop):

multithreadingqtglibcqthread

提问by yan bellavance

A call to clear on a QByteArray generates the following exception:

在 QByteArray 上调用 clear 会产生以下异常:

* glibc detected */home/yan/FPS2/FPS2: double free or corruption (fasttop):

* glibc 检测 */home/yan/FPS2/FPS2: double free or corruption (fasttop):

0 ?? 1 ??
2 free
3 QByteArray::clear()
4 FPSengine::getDatagrams
5 FPSengine::xmitData
6 FPSengine::getData
7 threadDatalog::run
8 ??
9 start_thread
10 clone
11 ?? 0

0 ?? 1 ??
2 免费
3 QByteArray::clear()
4 FPSengine::getDatagrams
5 FPSengine::xmitData
6 FPSengine::getData
7 threadDatalog::r​​un
8 ??
9 开始线程
10 克隆
11 ?? 0

is this a qt bug or could it have something to do with my code? I know QObjects arent thread safe (QT definition not multiple threads calling the same function of the same object instance)but my function has mutexes. Also I very rarely get this error even though the same function is called frequently. P.S. A way to prevent this is to env var MALLOC_CHECK_ 0

这是一个qt错误还是与我的代码有关?我知道 QObjects 不是线程安全的(QT 定义不是多个线程调用同一对象实例的同一函数)但我的函数有互斥锁。此外,即使经常调用相同的函数,我也很少收到此错误。PS 防​​止这种情况的一种方法是 env var MALLOC_CHECK_ 0

this url relates a similar problem and some posts seems to imply its caused by an incompatible version of glibc.

这个 url 涉及一个类似的问题,一些帖子似乎暗示它是由不兼容的 glibc 版本引起的。

*** glibc detected *** perl: double free or corruption (!prev): 0x0c2b7138 ***

*** 检测到 glibc *** perl: double free or corruption (!prev): 0x0c2b7138 ***

采纳答案by yan bellavance

this is caused by the fact the the application is multithreaded, the object belongs in the mainthread but is used in another thread, even though I used mutexes on the QBytearray the UDPsocket which uses it to do readDatagram is also in the mainthread...and yes I need that udpSocket to be in the main thread as well

这是由于应用程序是多线程的,该对象属于主线程但在另一个线程中使用,即使我在 QBytearray 上使用互斥锁,使用它来执行 readDatagram 的 UDPsocket 也在主线程中......和是的,我也需要将 udpSocket 放在主线程中

回答by Kaleb Pederson

It could be a number of different things, including referencing a temporary QByteArrayreturned by a function call, but it's unlikely (IMO) to be a bug in Qt.

它可能是许多不同的事情,包括引用QByteArray由函数调用返回的临时值,但它不太可能(IMO)是 Qt 中的错误。

Here's a few thoughts for debugging:

这里有一些调试的想法:

  • run it under Valgrind and see if it will highlight the problem
  • run your application against a version of Qt that has debug symbols available for it
  • enable core dumps and see if you get a core file
  • 在 Valgrind 下运行它,看看它是否会突出问题
  • 针对具有可用调试符号的 Qt 版本运行您的应用程序
  • 启用核心转储并查看是否获得核心文件

回答by captncraig

I highly doubt you have found a bug in qt. That error can occur for a number of reasons, but essential means you have a reference to memory that has already been freed. Run through debuggers and try and see what is causing the problem. Use gdb and valgrind and hopefully you can track down the problem.

我非常怀疑您是否在 qt 中发现了错误。发生该错误的原因有很多,但本质上意味着您引用了已释放的内存。运行调试器并尝试查看导致问题的原因。使用 gdb 和 valgrind,希望你能找到问题所在。