PDA

View Full Version : qvector.h, line 538: Out of memory, std::bad_alloc



HappyCoder
6th March 2017, 08:31
Hi,
we provide a software for our customers that can show either a graph or a table with
the measured values at a specific time. When i have big data and switch to table view
our software crashed with the message:



In file ..\..\include/QtCore/../../src/corelib/tools/qvector.h, line 538: Out of memory
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
exited with code 3


Our software crashes (Release) at around 1,8 GB memory usage (from Windows 7 task manager).

qvector.h (Qt 5.6.2)


template <typename T>
void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::AllocationOptions options)
{
Q_ASSERT(asize >= 0 && asize <= aalloc);
Data *x = d;

const bool isShared = d->ref.isShared();

if (aalloc != 0) {
if (aalloc != int(d->alloc) || isShared) {
QT_TRY {
// allocate memory
x = Data::allocate(aalloc, options);
Q_CHECK_PTR(x); // THIS IS LINE 538


and this is the code to fill the table


for(int u=itemList.at(i)->idx;u<itemList.at(i)->mData->values.size();u++){

if(ui->tableWidget->rowCount() < u+1)
ui->tableWidget->setRowCount(u+1);

QTableWidgetItem* itemt = new QTableWidgetItem(loc.toString(itemList.at(i)->mData->timestamps.at(u)));
itemt->setTextColor(itemList.at(i)->color);
ui->tableWidget->setItem(u,(i+1)*2-2,itemt);

QString tmp;
if(itemList.at(i)->mData->errorFlag.length() > u){
if(itemList.at(i)->mData->errorFlag.at(u) == 0){

tmp = loc.toString(itemList.at(i)->mData->values.at(u)*setManager->getPressureFactor());
}
else if(itemList.at(i)->mData->errorFlag.at(u) & errflgUR) // Error UR
tmp = tr("Underrange");
else if(itemList.at(i)->mData->errorFlag.at(u) & errflgOR) // Error OR
tmp = tr("Overrange");
else if(itemList.at(i)->mData->errorFlag.at(u) & errflgSEDIS ) // Error SEDIS
tmp = tr("Sensor disabled");
}

QTableWidgetItem* itemp = new QTableWidgetItem(tmp);
itemp->setTextColor(itemList.at(i)->color);
ui->tableWidget->setItem(u,(i+1)*2-1,itemp);

itemList.at(i)->idx = u;
}


Has someone any idea to improve our code or any other help is welcome?
HappyCoder

high_flyer
6th March 2017, 11:15
What did you try so far?
For example, did you try to run it with a small test data set?
If you run a debug build in a debugger, does it behave differently i.e doesn't crash, or crashes somewhere else?
If it still crashes while in debugger, have a look at the calls stack, and trace the last call in your own code, see if you get clues there.
Also, make sure you are not having an endless recursion, which also could crash with alloc memory errors.