Merge pull request #6 from sletta/next

[qtdeclarative] Fix crash on shutdown
MER: Fix memory corruption bug

(This patch can be removed when QTBUG-37834 is addressed upstream)

In QQmlData::destroyed(), release the compiledData after
destroying the context instead of before. The context
contains bindings which may contain references to the
compiledData. (At least with V4 bindings)

This might cause heap corruption in QV4Bindings::Binding::disconnect()
because it uses values from 'program' (one of the datas[] values
from a QQmlCompiledData) to possibly modify memory via sub->setActive().

The reads from a freed program are easily reproduced (just start
an app under lipstick and then close it; detected with valgrind).
I haven't witnessed any heap corruption from this but it may be
behind the occasional crashes of lipstick.
(cherry picked from commit 3cfbd9d3176cbbc95bdbe3712f4accdc1485ed55)
Revert "Squashed commit of the following:"

This reverts commit 69b5f133c52b0de0de3aba0bed6d727b5b3db00a.

This broke boosted applications.
Revert "Revert "Squashed commit of the following:""

This reverts commit 656155db64eeb770bd929338ef5416b96ca79a13.
Destroy render loop when QCoreApplication is cleaned up.

Doing it on 'aboutToQuit' meant we would clean it up whenever an
application ran QCoreApp::exec() which could be multiple times
per application run.

Change-Id: I59e06398a551ae7979e3832dff811937037fa106