Results 1 to 17 of 17

Thread: Memory allocation failure and crash in QVector

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Memory allocation failure and crash in QVector

    A memory request of that size will always fail on a regular computer...
    I am not sure, but QVector should assert when the allocation fails.
    Are you sure it is a seg fault and not an assert?

  2. #2
    Join Date
    Oct 2007
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Memory allocation failure and crash in QVector

    1. I especially selected such size to demonstrate the problem. But actually it can happen with any size under low memory conditions in OS.
    2. Will assertion help in release mode? I doubt.

    After short debug session I found that it crashes right in QVector's constructor:

    template <typename T>
    inline QVectorData *QVector<T>::malloc(int aalloc)
    {
    return static_cast<QVectorData *>(qMalloc(sizeof(Data) + (aalloc - 1) * sizeof(T)));
    }

    template <typename T>
    QVector<T>::QVector(int asize)
    {
    p = malloc(asize);
    d->ref.init(1);
    d->alloc = d->size = asize;
    d->sharable = true;
    d->capacity = false;
    if (QTypeInfo<T>::isComplex) {
    T* b = d->array;
    T* i = d->array + d->size;
    while (i != b)
    new (--i) T;
    } else {
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    qMemSet(d->array, 0, asize * sizeof(T)); // place where crash actually occurs
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    }
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.