Free the QFreeList object allocated memory on exit

This memory allocation was introduced in
314c83c0c2. With a compiler without thread
safe statics support mutex.cpp use a function named freelist() to create
the global QFreeList object. it will be created when the first time it was
accessed, but will never be released. This patch use Q_DESTRUCTOR_FUNCTION
to delete this object.

Task-number: QTBUG-48359
Change-Id: I4e4716930930aa98630101a1f96de6a7672af9cb
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
jian liang 2015-09-20 23:08:59 +08:00
parent 843199f303
commit be2e0f75ae
1 changed files with 11 additions and 4 deletions

View File

@ -571,19 +571,26 @@ FreeList *freelist()
return &list;
}
#else
static QBasicAtomicPointer<FreeList> freeListPtr;
FreeList *freelist()
{
static QAtomicPointer<FreeList> list;
FreeList *local = list.loadAcquire();
FreeList *local = freeListPtr.loadAcquire();
if (!local) {
local = new FreeList;
if (!list.testAndSetRelease(0, local)) {
if (!freeListPtr.testAndSetRelease(0, local)) {
delete local;
local = list.loadAcquire();
local = freeListPtr.loadAcquire();
}
}
return local;
}
static void qFreeListDeleter()
{
delete freeListPtr.load();
}
Q_DESTRUCTOR_FUNCTION(qFreeListDeleter)
#endif
}