diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-08-08 14:44:51 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-09 03:26:05 +0200 |
commit | 649cd987439d87875c05983908823aa3062cdee9 (patch) | |
tree | 76b32ac0b6e8e05069a11bfb42288c999b538559 | |
parent | 1ecef1ea354c539ca57532a2944bcaa9842db500 (diff) |
Remove use of ::free from qlist.h
The memory is allocated in qlist.cpp, so it should be freed in
qlist.cpp. Freeing it in qlist.cpp ties our hands about future
improvements to the allocator.
In addition, silence the warning by the too-smart-for-its-own-good GCC
that we're trying to free a non-heap object:
qlist.h:763:14: warning: attempt to free a non-heap object "QListData::shared_null" [-Wfree-nonheap-object]
The warning is wrong. It should say "possibly" somewhere because GCC
failed to account for all conditions in the path to free().
Change-Id: I34a6c16bba9a2197fc83eb3c7a63ae06fb25bf15
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
-rw-r--r-- | src/corelib/tools/qlist.cpp | 6 | ||||
-rw-r--r-- | src/corelib/tools/qlist.h | 12 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index 72924ef84c..ad33010faf 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -154,6 +154,12 @@ void QListData::realloc(int alloc) d->begin = d->end = 0; } +void QListData::dispose(Data *d) +{ + Q_ASSERT(!d->ref.isShared()); + free(d); +} + // ensures that enough space is available to append n elements void **QListData::append(int n) { diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index ad94781b6f..49f0ec750f 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -76,6 +76,8 @@ struct Q_CORE_EXPORT QListData { Data *detach(int alloc); Data *detach_grow(int *i, int n); void realloc(int alloc); + inline void dispose() { dispose(d); } + static void dispose(Data *d); static const Data shared_null; Data *d; void **erase(void **xi); @@ -664,7 +666,7 @@ Q_OUTOFLINE_TEMPLATE typename QList<T>::Node *QList<T>::detach_helper_grow(int i node_copy(reinterpret_cast<Node *>(p.begin()), reinterpret_cast<Node *>(p.begin() + i), n); } QT_CATCH(...) { - free(d); + p.dispose(); d = x; QT_RETHROW; } @@ -674,7 +676,7 @@ Q_OUTOFLINE_TEMPLATE typename QList<T>::Node *QList<T>::detach_helper_grow(int i } QT_CATCH(...) { node_destruct(reinterpret_cast<Node *>(p.begin()), reinterpret_cast<Node *>(p.begin() + i)); - free(d); + p.dispose(); d = x; QT_RETHROW; } @@ -693,7 +695,7 @@ Q_OUTOFLINE_TEMPLATE void QList<T>::detach_helper(int alloc) QT_TRY { node_copy(reinterpret_cast<Node *>(p.begin()), reinterpret_cast<Node *>(p.end()), n); } QT_CATCH(...) { - free(d); + p.dispose(); d = x; QT_RETHROW; } @@ -718,7 +720,7 @@ Q_OUTOFLINE_TEMPLATE QList<T>::QList(const QList<T> &l) struct Cleanup { Cleanup(QListData::Data *d) : d_(d) {} - ~Cleanup() { if (d_) free(d_); } + ~Cleanup() { if (d_) QListData::dispose(d_); } QListData::Data *d_; } tryCatch(d); @@ -760,7 +762,7 @@ Q_OUTOFLINE_TEMPLATE void QList<T>::dealloc(QListData::Data *data) { node_destruct(reinterpret_cast<Node *>(data->array + data->begin), reinterpret_cast<Node *>(data->array + data->end)); - free(data); + QListData::dispose(data); } |