summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authormread <qt-info@nokia.com>2009-08-06 09:38:54 (GMT)
committermread <qt-info@nokia.com>2009-08-06 09:38:54 (GMT)
commit48018d7e8b016d14c27219dbba41ca229870d00b (patch)
tree33ffe2cffb7bc19aaadbda4100c43f99e43a2f9f /src/corelib
parent252e1e7c98eca34add9f4531edf800fc1b47fde6 (diff)
downloadQt-48018d7e8b016d14c27219dbba41ca229870d00b.zip
Qt-48018d7e8b016d14c27219dbba41ca229870d00b.tar.gz
Qt-48018d7e8b016d14c27219dbba41ca229870d00b.tar.bz2
fixing memory leaks in dir iterator
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qdiriterator.cpp27
-rw-r--r--src/corelib/io/qdiriterator.h2
2 files changed, 21 insertions, 8 deletions
diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp
index 582d657..12fe258 100644
--- a/src/corelib/io/qdiriterator.cpp
+++ b/src/corelib/io/qdiriterator.cpp
@@ -99,6 +99,18 @@
QT_BEGIN_NAMESPACE
+class QDirIteratorPrivateIteratorStack : public QStack<QAbstractFileEngineIterator *>
+{
+public:
+ ~QDirIteratorPrivateIteratorStack();
+};
+
+QDirIteratorPrivateIteratorStack::~QDirIteratorPrivateIteratorStack()
+{
+ qDeleteAll(*this);
+}
+
+
class QDirIteratorPrivate
{
public:
@@ -113,8 +125,8 @@ public:
bool matchesFilters(const QString &fileName, const QFileInfo &fi) const;
QSet<QString> visitedLinks;
- QAbstractFileEngine *engine;
- QStack<QAbstractFileEngineIterator *> fileEngineIterators;
+ QScopedPointer<QAbstractFileEngine> engine;
+ QDirIteratorPrivateIteratorStack fileEngineIterators;
QString path;
QFileInfo nextFileInfo;
//This fileinfo is the current that we will return from the public API
@@ -135,7 +147,7 @@ public:
*/
QDirIteratorPrivate::QDirIteratorPrivate(const QString &path, const QStringList &nameFilters,
QDir::Filters filters, QDirIterator::IteratorFlags flags)
- : engine(0), path(path), nextFileInfo(path), iteratorFlags(flags), followNextDir(false), first(true), done(false)
+ : path(path), nextFileInfo(path), iteratorFlags(flags), followNextDir(false), first(true), done(false)
{
if (filters == QDir::NoFilter)
filters = QDir::AllEntries;
@@ -151,7 +163,6 @@ QDirIteratorPrivate::QDirIteratorPrivate(const QString &path, const QStringList
*/
QDirIteratorPrivate::~QDirIteratorPrivate()
{
- delete engine;
}
/*!
@@ -170,7 +181,11 @@ void QDirIteratorPrivate::pushSubDirectory(const QString &path, const QStringLis
}
}
- if (engine || (engine = QAbstractFileEngine::create(this->path))) {
+ if (engine.isNull()) {
+ engine.reset(QAbstractFileEngine::create(this->path));
+ }
+
+ if (!engine.isNull()) {
engine->setFileName(path);
QAbstractFileEngineIterator *it = engine->beginEntryList(filters, nameFilters);
if (it) {
@@ -461,8 +476,6 @@ QDirIterator::QDirIterator(const QString &path, const QStringList &nameFilters,
*/
QDirIterator::~QDirIterator()
{
- qDeleteAll(d->fileEngineIterators);
- delete d;
}
/*!
diff --git a/src/corelib/io/qdiriterator.h b/src/corelib/io/qdiriterator.h
index 3117bf9..2639e02 100644
--- a/src/corelib/io/qdiriterator.h
+++ b/src/corelib/io/qdiriterator.h
@@ -84,7 +84,7 @@ public:
private:
Q_DISABLE_COPY(QDirIterator)
- QDirIteratorPrivate *d;
+ QScopedPointer<QDirIteratorPrivate> d;
friend class QDir;
};