[Interest] Internal Qt bug or incorrect user API call?

Thiago Macieira thiago.macieira at intel.com
Thu Aug 28 18:45:50 CEST 2014

On Friday 08 August 2014 18:46:09 T Stutts wrote:
> What does this line
> <https://qt.gitorious.org/qt/digia-qt/source/705b0f958a6071341b10cbd51917e13
> 78356491b:src/corelib/tools/qvarlengtharray.h#L194this> *[qt.gitorious.org
> <http://qt.gitorious.org>]* line do?
> I am referring to the line
>    1. new (ptr+(s++)) T(*abuf++);

That's a call to the placement operator new, at ptr+s, calling T's copy 
constructor with a parameter of *abuf. Before the end of the statement, both s 
and abuf are incremented.

> It looks to me like an explicit memory leak (see new()
> <http://en.cppreference.com/w/cpp/language/new> *[en.cppreference.com
> <http://en.cppreference.com>]*).
> It expressly allocates dynamic memory and does not store the pointer
> anywhere, unless Qt has its own allocation implementation (ie
> set_new_handler()
> <http://en.cppreference.com/w/cpp/memory/new/set_new_handler>*[en.cppreferen
> ce.com <http://en.cppreference.com>]*).

Please don't use HTML in mailing lists and, more importantly, please make sure 
that the plain text form is readable. It's very hard to read your email with 
those embedded links and unnecessary * * markup.

The function is not allocating memory. That's the placement operator new.

> I am asking because I am seeing random crashes in my ODBC application when
> retrieving an output parameter.
> Tracing the call, it's coming from an access violation attempting to read
> the location of*abuf* in the above *append()* function called from this
> line in QODBCResult::exec()
> <https://qt.gitorious.org/qt/digia-qt/source/705b0f958a6071341b10cbd51917e13
> 78356491b:src/sql/drivers/odbc/qsql_odbc.cpp#L1655>*[qt.gitorious.org
> <http://qt.gitorious.org>]*.
>    1. array.append((SQLTCHAR *)first.constData(), first.size());
> Normally this pointer seems correct, except when it crashes (debugging in
> Visual Studio 2012) with a read access violation because this pointer is
> apparently unreadable. Stepping back to *QODBCResult::exec()*, the
> variables seem normal and the output parameter seems to have been retrieved
> properly.
> What is causing this? How can I fix it?

Please provide a testcase so we can look into why that crash is happening. It 
has nothing to do with the QVarLengthArray line you pasted.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

More information about the Interest mailing list