LINUX.ORG.RU

Segmentation fault. 0x77052ace in ntdll!RtlFreeHeap ()

 , , ,


0

2

В windows в приложении на Qt5 вылетает такая ошибка:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 3960.0xca0]
0x77052ace in ntdll!RtlFreeHeap () from C:\Windows\SYSTEM32\ntdll.dll

Появляется после создания относительно большого количества тредов (десятки штук).

Может ли эта ошибка быть связана с исчерпанием лимита тредов на процесс?

★★

Погуглил. Без спец. ухищрений в винде около 2000 потоков на процесс.

У меня гораздо меньше.

SaBo ★★
() автор топика
Последнее исправление: SaBo (всего исправлений: 1)
Ответ на: комментарий от anonymous

Я не нашел в выводе дебага треда по такому адресу.

SaBo ★★
() автор топика

Вот ещё ошибка при тех же обстоятельствах:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1300.0x1154]
0x770518d6 in ntdll!RtlAllocateHeap () from C:\Windows\SYSTEM32\ntdll.dll

#0  0x770518d6 in ntdll!RtlAllocateHeap () from C:\Windows\SYSTEM32\ntdll.dll
#1  0x77051154 in ntdll!RtlAllocateHeap () from C:\Windows\SYSTEM32\ntdll.dll
#2  0x770f5b4a in ntdll!RtlpNtSetValueKey ()
   from C:\Windows\SYSTEM32\ntdll.dll
#3  0x7709762a in ntdll!RtlDestroyMemoryBlockLookaside ()
   from C:\Windows\SYSTEM32\ntdll.dll
#4  0x77051154 in ntdll!RtlAllocateHeap () from C:\Windows\SYSTEM32\ntdll.dll
#5  0x751cb197 in msvcrt!malloc () from C:\Windows\SYSTEM32\msvcrt.dll
#6  0x003442f0 in libgcc_s_dw2-1!_Unwind_Backtrace ()
   from C:\Qt\Qt5.5.1\Tools\mingw492_32\opt\bin\libgcc_s_dw2-1.dll
#7  0x00344b04 in libgcc_s_dw2-1!_Unwind_Find_FDE ()
   from C:\Qt\Qt5.5.1\Tools\mingw492_32\opt\bin\libgcc_s_dw2-1.dll
#8  0x00341a3e in libgcc_s_dw2-1!.enable_execute_stack ()
   from C:\Qt\Qt5.5.1\Tools\mingw492_32\opt\bin\libgcc_s_dw2-1.dll
#9  0x00342c6d in libgcc_s_dw2-1!.enable_execute_stack ()
   from C:\Qt\Qt5.5.1\Tools\mingw492_32\opt\bin\libgcc_s_dw2-1.dll
#10 0x0034339e in libgcc_s_dw2-1!_Unwind_RaiseException ()
   from C:\Qt\Qt5.5.1\Tools\mingw492_32\opt\bin\libgcc_s_dw2-1.dll
#11 0x02407d65 in libstdc++-6!.cxa_throw ()
   from C:\Qt\Qt5.5.1\5.5\mingw492_32\bin\libstdc++-6.dll
#12 0x6b78b1a4 in qBadAlloc () at global\qglobal.cpp:2946
#13 0x6b7f615b in QString::QString (this=0x1a70ce64, unicode=0x1a389d80,
    size=10) at tools\qstring.cpp:1458
#14 0x6b7fb35a in QString::mid (this=0x1a70d140, position=220, n=10)
    at tools\qstring.cpp:4215
#15 0x0c409464 in QSqlResultPrivate::namedToPositionalBinding (
    this=0x24f27440, query=...) at kernel\qsqlresult.cpp:155
#16 0x0c409c8c in QSqlResult::savePrepare (this=0x1f032e10, query=...)
    at kernel\qsqlresult.cpp:594
#17 0x0c402e68 in QSqlQuery::prepare (this=0x1a70cfd8, query=...)
    at kernel\qsqlquery.cpp:980
#18 0x0044ca91 in GoodsUpdater::updateGood (this=0x17d74358, session=...,
    clientId=..., page=2, pageSize=1000, lastUpdate=...)
    at src/Updaters/GoodsUpdater.cpp:129
#19 0x0044b74a in GoodsUpdater::updateGoods (this=0x17d74358, session=...,
    clientId=...) at src/Updaters/GoodsUpdater.cpp:54
#20 0x0044b3ba in GoodsUpdater::update (this=0x17d74358)
    at src/Updaters/GoodsUpdater.cpp:31
#21 0x00457539 in GoodsUpdater::qt_static_metacall (_o=0x17d74358,
    _c=QMetaObject::InvokeMetaMethod, _id=0, _a=0x24bd5b08)
    at build/Debug_Win32/MinGW-Qt5.5.1-Linux/moc/moc_GoodsUpdater.cpp:69
#22 0x6b9008b4 in QMetaCallEvent::placeMetaCall (this=0x24edc010,
    object=0x17d74358) at kernel\qobject.cpp:486
#23 0x6b901619 in QObject::event (this=0x17d74358, e=0x24edc010)
    at kernel\qobject.cpp:1239
#24 0x0c9bf34d in QApplicationPrivate::notify_helper (this=0x162c37b8,
    receiver=0x17d74358, e=0x24edc010) at kernel\qapplication.cpp:3716
#25 0x0c9bcd03 in QApplication::notify (this=0x28fe14, receiver=0x17d74358,
    e=0x24edc010) at kernel\qapplication.cpp:3160
#26 0x6b8ded92 in QCoreApplication::notifyInternal (this=0x28fe14,
    receiver=0x17d74358, event=0x24edc010) at kernel\qcoreapplication.cpp:965
#27 0x6b9d73e7 in QCoreApplication::sendEvent (receiver=0x17d74358,
    event=0x24edc010)
    at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:224
#28 0x6b8dff2a in QCoreApplicationPrivate::sendPostedEvents (receiver=0x0,
    event_type=0, data=0x17d6dc50) at kernel\qcoreapplication.cpp:1593
#29 0x6b92ed28 in QEventDispatcherWin32::sendPostedEvents (this=0x17d7dce0)
    at kernel\qeventdispatcher_win.cpp:1241
#30 0x6b92c033 in qt_internal_proc(HWND__*, unsigned int, unsigned int, long)@16
 (hwnd=0x95041c, message=1025, wp=0, lp=0)
    at kernel\qeventdispatcher_win.cpp:414
#31 0x74b98e71 in USER32!CallNextHookEx () from C:\Windows\SYSTEM32\user32.dll
#32 0x74b990d1 in USER32!CallNextHookEx () from C:\Windows\SYSTEM32\user32.dll
#33 0x74b9a62a in USER32!GetMessageW () from C:\Windows\SYSTEM32\user32.dll
#34 0x74b9a680 in USER32!DispatchMessageW ()
   from C:\Windows\SYSTEM32\user32.dll
#35 0x6b92d611 in QEventDispatcherWin32::processEvents (this=0x17d7dce0,
    flags=...) at kernel\qeventdispatcher_win.cpp:817
#36 0x6b8dcc68 in QEventLoop::processEvents (this=0x1a70feb8, flags=...)
    at kernel\qeventloop.cpp:128
#37 0x6b8dcefb in QEventLoop::exec (this=0x1a70feb8, flags=...)
    at kernel\qeventloop.cpp:204
#38 0x6b79719d in QThread::exec (this=0x17cdbb90) at thread\qthread.cpp:503
#39 0x6b7972fd in QThread::run (this=0x17cdbb90) at thread\qthread.cpp:570
#40 0x6b799da8 in QThreadPrivate::start(void*)@4 (arg=0x17cdbb90)
    at thread\qthread_win.cpp:367
#41 0x751d7fb0 in msvcrt!_cexit () from C:\Windows\SYSTEM32\msvcrt.dll
#42 0x17cdbb90 in ?? ()
#43 0x751d80f5 in msvcrt!_beginthreadex () from C:\Windows\SYSTEM32\msvcrt.dll
#44 0x74837c04 in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\SYSTEM32\kernel32.dll
#45 0x7706ad5f in ntdll!RtlInitializeExceptionChain ()
   from C:\Windows\SYSTEM32\ntdll.dll
#46 0x7706ad2a in ntdll!RtlInitializeExceptionChain ()
   from C:\Windows\SYSTEM32\ntdll.dll
#47 0x00000000 in ?? ()
SaBo ★★
() автор топика
Ответ на: комментарий от SaBo

Вот, какой код на этой строке src/Updaters/GoodsUpdater.cpp:129:

query.prepare("INSERT OR REPLACE INTO 'goods' ("
                            "'session', 'client_id', 'good_id', 'good', 'good_name', 'article', 'barcode', 'is_favourite', 'good_name_lower', 'article_lower', 'barcode_lower') "
                            "VALUES ('', :client_id, :good_id, :good, :good_name, :article, :barcode, :is_favourite, :good_name_lower, :article_lower, :barcode_lower);");

Код исполняется в отдельном потоке.

SaBo ★★
() автор топика
Ответ на: комментарий от SaBo

Там даже так:

QSqlQuery query;

if (!good.value(QString("fdel")).toBool()) {
    query.prepare("INSERT OR REPLACE INTO 'goods' ("
    ...
} else {
    query.prepare("DELETE FROM goods WHERE client_id = :client_id AND good_id = :good_id");
    ...
}

if (!query.exec()) {
    ...
}

Может такая ерунда происходить из-за того, что QSqlQuery query объявлен до if?

SaBo ★★
() автор топика
Последнее исправление: SaBo (всего исправлений: 1)
Ответ на: комментарий от SaBo

Вот ещё такую словил:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1004.0x1f4]
0x770220f4 in ntdll!RtlSetUserValueHeap () from C:\Windows\SYSTEM32\ntdll.dll

#0  0x770220f4 in ntdll!RtlSetUserValueHeap ()
   from C:\Windows\SYSTEM32\ntdll.dll
#1  0x3e3079be in ?? ()
#2  0x1c1880f0 in ?? ()
#3  0x77051eca in ntdll!RtlFreeHeap () from C:\Windows\SYSTEM32\ntdll.dll
#4  0x770f6527 in ntdll!RtlpNtSetValueKey ()
   from C:\Windows\SYSTEM32\ntdll.dll
#5  0x77096846 in ntdll!RtlDestroyMemoryBlockLookaside ()
   from C:\Windows\SYSTEM32\ntdll.dll
#6  0x77051eca in ntdll!RtlFreeHeap () from C:\Windows\SYSTEM32\ntdll.dll
#7  0x751cb0f9 in msvcrt!free () from C:\Windows\SYSTEM32\msvcrt.dll
#8  0x162f0000 in ?? ()
#9  0x6b7d1751 in QHashData::freeNode (this=0x1a51ab28, node=0x1c1880f8)
    at tools\qhash.cpp:408
#10 0x6b7d1a18 in QHashData::free_helper (this=0x1a51ab28,
    node_delete=0xc3fb2b4 <QHash<QString, QList<int> >::deleteNode2(QHashData::N
ode*)>) at tools\qhash.cpp:492
#11 0x0c3fb426 in QHash<QString, QList<int> >::freeData (this=0x1a606698,
    x=0x1a51ab28) at ../../include/QtCore/../../src/corelib/tools/qhash.h:621
#12 0x0c3fb479 in QHash<QString, QList<int> >::~QHash (this=0x1a606698,
    __in_chrg=<optimized out>)
    at ../../include/QtCore/../../src/corelib/tools/qhash.h:342
#13 0x0c3f8bac in QSqlResultPrivate::~QSqlResultPrivate (this=0x1a606650,
    __in_chrg=<optimized out>) at kernel/qsqlresult_p.h:77
#14 0x0c3f8b73 in QSqlResultPrivate::~QSqlResultPrivate (this=0x1a606650,
    __in_chrg=<optimized out>) at kernel/qsqlresult_p.h:77
#15 0x0c3e98b4 in QSqlResult::~QSqlResult (this=0x17f09a28,
    __in_chrg=<optimized out>) at kernel\qsqlresult.cpp:248
#16 0x0c3eb2d8 in QSqlCachedResult::~QSqlCachedResult (this=0x17f09a28,
    __in_chrg=<optimized out>) at kernel\qsqlcachedresult.cpp:142
#17 0x19402b3f in QSQLiteResult::~QSQLiteResult (this=0x17f09a28,
    __in_chrg=<optimized out>)
    at ..\..\..\sql\drivers\sqlite\qsql_sqlite.cpp:346
#18 0x19402b6b in QSQLiteResult::~QSQLiteResult (this=0x17f09a28,
    __in_chrg=<optimized out>)
    at ..\..\..\sql\drivers\sqlite\qsql_sqlite.cpp:353
#19 0x0c3e191e in QSqlQueryPrivate::~QSqlQueryPrivate (this=0x1a668488,
    __in_chrg=<optimized out>) at kernel\qsqlquery.cpp:88
#20 0x0c3e1983 in QSqlQuery::~QSqlQuery (this=0x1a93cfd8,
    __in_chrg=<optimized out>) at kernel\qsqlquery.cpp:239
#21 0x0044dad6 in GoodsUpdater::updateGood (this=0x17ebe8b8, session=...,
    clientId=..., page=3, pageSize=1000, lastUpdate=...)
    at src/Updaters/GoodsUpdater.cpp:153
#22 0x0044b74a in GoodsUpdater::updateGoods (this=0x17ebe8b8, session=...,
    clientId=...) at src/Updaters/GoodsUpdater.cpp:54
#23 0x0044b3ba in GoodsUpdater::update (this=0x17ebe8b8)
    at src/Updaters/GoodsUpdater.cpp:31
#24 0x00457539 in GoodsUpdater::qt_static_metacall (_o=0x17ebe8b8,
    _c=QMetaObject::InvokeMetaMethod, _id=0, _a=0x1a56f988)
    at build/Debug_Win32/MinGW-Qt5.5.1-Linux/moc/moc_GoodsUpdater.cpp:69
#25 0x6b9008b4 in QMetaCallEvent::placeMetaCall (this=0x17f04be8,
    object=0x17ebe8b8) at kernel\qobject.cpp:486
#26 0x6b901619 in QObject::event (this=0x17ebe8b8, e=0x17f04be8)
    at kernel\qobject.cpp:1239
#27 0x0c99f34d in QApplicationPrivate::notify_helper (this=0x162f37b8,
    receiver=0x17ebe8b8, e=0x17f04be8) at kernel\qapplication.cpp:3716
#28 0x0c99cd03 in QApplication::notify (this=0x28fe14, receiver=0x17ebe8b8,
    e=0x17f04be8) at kernel\qapplication.cpp:3160
#29 0x6b8ded92 in QCoreApplication::notifyInternal (this=0x28fe14,
    receiver=0x17ebe8b8, event=0x17f04be8) at kernel\qcoreapplication.cpp:965
#30 0x6b9d73e7 in QCoreApplication::sendEvent (receiver=0x17ebe8b8,
    event=0x17f04be8)
    at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:224
#31 0x6b8dff2a in QCoreApplicationPrivate::sendPostedEvents (receiver=0x0,
    event_type=0, data=0x17eef3b0) at kernel\qcoreapplication.cpp:1593
#32 0x6b92ed28 in QEventDispatcherWin32::sendPostedEvents (this=0x17f018c8)
    at kernel\qeventdispatcher_win.cpp:1241
#33 0x6b92c033 in qt_internal_proc(HWND__*, unsigned int, unsigned int, long)@16
 (hwnd=0x6d02c8, message=1025, wp=0, lp=0)
    at kernel\qeventdispatcher_win.cpp:414
#34 0x74b98e71 in USER32!CallNextHookEx () from C:\Windows\SYSTEM32\user32.dll
#35 0x74b990d1 in USER32!CallNextHookEx () from C:\Windows\SYSTEM32\user32.dll
#36 0x74b9a62a in USER32!GetMessageW () from C:\Windows\SYSTEM32\user32.dll
#37 0x74b9a680 in USER32!DispatchMessageW ()
   from C:\Windows\SYSTEM32\user32.dll
#38 0x6b92d611 in QEventDispatcherWin32::processEvents (this=0x17f018c8,
    flags=...) at kernel\qeventdispatcher_win.cpp:817
#39 0x6b8dcc68 in QEventLoop::processEvents (this=0x1a93feb8, flags=...)
    at kernel\qeventloop.cpp:128
#40 0x6b8dcefb in QEventLoop::exec (this=0x1a93feb8, flags=...)
    at kernel\qeventloop.cpp:204
#41 0x6b79719d in QThread::exec (this=0x17ebb1c0) at thread\qthread.cpp:503
#42 0x6b7972fd in QThread::run (this=0x17ebb1c0) at thread\qthread.cpp:570
#43 0x6b799da8 in QThreadPrivate::start(void*)@4 (arg=0x17ebb1c0)
    at thread\qthread_win.cpp:367
#44 0x751d7fb0 in msvcrt!_cexit () from C:\Windows\SYSTEM32\msvcrt.dll
#45 0x17ebb1c0 in ?? ()
#46 0x751d80f5 in msvcrt!_beginthreadex () from C:\Windows\SYSTEM32\msvcrt.dll
#47 0x74837c04 in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\SYSTEM32\kernel32.dll
#48 0x7706ad5f in ntdll!RtlInitializeExceptionChain ()
   from C:\Windows\SYSTEM32\ntdll.dll
#49 0x7706ad2a in ntdll!RtlInitializeExceptionChain ()
   from C:\Windows\SYSTEM32\ntdll.dll
#50 0x00000000 in ?? ()

src/Updaters/GoodsUpdater.cpp:153:

81: int GoodsUpdater::updateGood(const QString &session, const QString &clientId, int page, int pageSize, const QString lastUpdate) {
...
153: return -1;
SaBo ★★
() автор топика
Ответ на: комментарий от Deleted

Кроссплатформенное. Под линуксом такой проблемы не наблюдается. Да и не под всяким виндовсом такая проблема наблюдается...

SaBo ★★
() автор топика
Ответ на: комментарий от SaBo

Наверно, надо в каждом потоке переподключаться к SQLite?

Или использовать блокировки, чтобы исключить одновременный доступ из нескольких потоков к одному объекту. Тут на самом деле надо читать документацию на тему многопоточности в различных компонентах Qt.

Deleted
()
Ответ на: комментарий от SaBo


Is SQLite thread-safe?

Short answer: Yes

Medium length answer:

Be sure to recompile with -DTHREADSAFE=1
Do not use the same database connection at the same time in more than one thread.
On some operating systems, a database connection should always be used in the same thread in which it was originally created.
There are a few features of SQLite that are not threadsafe. Avoid those features.



Подробнее тут

AF ★★★
()
Ответ на: комментарий от Deleted

Нет, не запускал. Сегодня посмотрю.

SaBo ★★
() автор топика
Ответ на: комментарий от AF

Благодарю. Попробую разнести подключения.

SaBo ★★
() автор топика
Ответ на: комментарий от SaBo

Под линуксом такой проблемы не наблюдается.

Ну дак на винфак, какого это здесь делает?

false ★★★★★
()

C:\Windows\SYSTEM32\ntdll.dll
lor

anonymous
()

Что-то я не понимаю, как из треда правильно восстанавливать соединение.

int main(int argc, char** argv) {
...
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "DB1");
    db.setHostName("localhost");
...
void MyThread::run() {
    QSqlDatabase db(QSqlDatabase::database("DB1"));
    if (db.open()) {
    ...
}

Такой код правильный?

SaBo ★★
() автор топика
Ответ на: комментарий от SaBo
QSqlDatabase db()
{
    class ThreadDb
    {
        public:
            QString name;
            ThreadDb()
            {
                name = QString("db-%1").arg(reinterpret_cast<unsigned long long>(QThread::currentThread()), 8, 16, QChar('0'));
                QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", name);
                db.setConnectOptions("MYSQL_OPT_RECONNECT=1");
                db.setDatabaseName(cfg["mysql.database"]);
                if (!db.open(cfg["mysql.username"], cfg["mysql.password"])) DB_THROW(db);
            }
            ~ThreadDb()
            {
                QSqlDatabase::removeDatabase(name);
            }
            QSqlDatabase db()
            {
                return QSqlDatabase::database(name);
            }

    };
    static QThreadStorage<ThreadDb> db;
    return db.localData().db();
}
vzzo ★★★
()
Ответ на: комментарий от vzzo

Благодарю!

Похоже, что проблема решена.

SaBo ★★
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.