Patch: Fix KEncodingProber crashiness
thiago at kde.org
Fri Mar 20 22:17:31 GMT 2009
Jeff Mitchell wrote:
>Does the .data() call on a QByteArray return a temporary? I thought it
>returned a deep copy that was safe for e.g. passing outside of a
No, it returns the address of its own internal byte array. It's allocated
on the heap.
The problem is... the data is deallocated when the QByteArray goes out of
scope, which is just before the function returns. So the pointer returned
is always a dangling pointer.
>So, if QByteArray::data is returning the address of a temporary, do you
>have a recommended Right Way(TM) fix? Or should I simply return that
>part to strdup?
Scrap this function. Really, remove it. Or mark it as deprecated, non-
working and make it return 0 (it's safe to delete 0).
Make a new function that returns QByteArray.
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 189 bytes
Desc: This is a digitally signed message part.
More information about the kde-core-devel