QString qBadAlloc()



  • Hello,
    I run into qBadAlloc() for QString aka "out of memory".

    Situation:
    I have list like QList<QHash<QString, QString> > values; List contains hash of various properties including QPixmap serialized data (either as base64() or hex() it doesn't mater in regards to bug that I'm facing)

    Then from such list XML is created and problem occur:
    QXmlStreamWriter crashes on me in QXmlStreamWriter ->writeAttribute(key, value);

    Crash is in:
    @
    void QString::reallocData(uint alloc, bool grow) {
    ...
    Data *p = static_cast<Data *>(::realloc(d, sizeof(Data) + alloc * sizeof(QChar)));
    Q_CHECK_PTR(p); <- QT_THROW(std::bad_alloc());
    @

    std::bad_alloc() is thrown.

    QXmlStreamWriter is using QString as IO Device.
    Same crash happens when I used QByteArray and QBuffer just in different class.

    At the point of crash QString that is used by QXmlStreamWriter contains around 56MB of data and is appending 19MB data (QPixmap data). Application uses around 850MB of RAM - system has 8GB.

    I tested it on clean project and I can create XML (i.e. write it via QFile to HDD) of size 150MB, so it's probably problem with heap size.

    In application I can control QPixmap serialization size (using compression) and when I do reduce size of serialized QPixmap application works without crash.

    And kicker - this don't crash on Mac and Linux, only happens on Windows.
    Code for this serialization is in separate thread and initially I thought that maybe thread heap size is exceeding it's max limit, but when code is run from main thread crash occurs at the same place.

    Any idea what can cause this?

    Any suggestions are more then welcome.
    Thanks in advance.

    UPDATE: QList is valid at the time of XML creation and contains around 330MB of data.


  • Lifetime Qt Champion

    Hi,

    Are you by any chance running your application in 32bit on Windows ?



  • This is 32bit code running on 64bit OS.


  • Lifetime Qt Champion

    Sounds like your application might be hitting the 2GB RAM limit for 32bit processes



  • I tested it with SysInternals and Win8 "Task Manager" and mem tops to 850MB. Maybe issue with update, but hitting 2GB would explained situation.

    Thanks for the suggestion will check out with Valgrind.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.