Fix memleak in QBinaryJson::to{Raw,Binary}Data()
In Qt 5, the code belonged to QJsonDocument, and the memory was managed
by QJsonDocumentPrivate, which correctly cleaned it up in the d-tor.
However, when moved to Qt5Compat in Qt 6, the code simply became a
namespace with a bunch of free functions, so the underlying d-ptr is
gone. As a result, QBinaryJson::toRawData() simply hands a pointer to
the user, and it's now their responsibility to free the memory.
In case of QBinaryJson::toBinaryData(), the pointer is used to construct
a QByteArray (which did another copy), and was never freed afterwards.
That's a memory leak on the Qt side.
This patch fixes the memleak in QBinaryJson::toBinaryData(), and also
documents that the user has to free the memory obtained from
QBinaryJson::toRawData(). It also adds a qWarning() to the toRawData()
function, to steer the users towards toBinaryData() usage.
A follow-up patch will deprecate toRawData() immediately in 6.12.
Since toRawData() was used in toBinaryData() implementation, the
patch introduces a new static toRawDataHelper() that actually contains
all the logic.
The tests are also fixed to avoid memory leaks.
Amends the introduction of the code in Qt5Compat repo (Qt 6.0).
Fixes: QTBUG-149054
Pick-to: 6.12 6.11 6.8 6.5
Change-Id: If376d19f9788c753e29fd237abf7849307491504
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>