stack corruption in the webservice code

Thiago Macieira thiago at
Tue Dec 10 10:40:54 UTC 2013

On terça-feira, 10 de dezembro de 2013 10:18:07, Linus Torvalds wrote:
> Basically, every time you convert from QString to a "normal" string,
> you need to keep the QString around as long as that string is used. Or
> do a strdup(). Or just not convert at all, and keep it as a QString,
> so that the compiler will do the proper liveness analysis and keep it
> around.

Actually, you need to keep the QByteArray temporary.

	QByteArray tempfileBA = tempfileQ.toLocal8Bit();
	tempfile = tempfileBA.constData();

It's the QByteArray that owns the memory block. QByteArray is basically a 
glorified on-scope-exit-call-free() object :-)

> Too bad we don't get compiler warnings for things like this. And
> apparently malloc library debugging doesn't work very well for
> automatic C++ objects (since the compiler presumably just allocates
> them on the stack).

Valgrind is able to catch them. It will tell you that you're accessing a 
memory block freed inside ~QByteArray.

The tool that Lubomir used said the memory was freed, but didn't say where. 
Valgrind does that.

Thiago Macieira - thiago (AT) - thiago (AT)
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <>

More information about the subsurface mailing list