From da3bf86ecea14a8658601803e14820a28e7470d6 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Mon, 30 Nov 2009 17:08:53 +0100 Subject: Fixes a crash on Mac with QFileInfo. realpath() crashes on mac if the input file path is the root ("/") - on 10.6 calling a free on the returned value shows a warning saying the memory was not allocated. To workaround that just added a special case - if the input string is '/', we don't need to use realpath as we already know that the path is canonical. Reviewed-by: Prasanth --- src/corelib/io/qfsfileengine.cpp | 6 +++++- tests/auto/qfileinfo/tst_qfileinfo.cpp | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index efc09a0..b8f6e2c 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -139,7 +139,11 @@ QString QFSFileEnginePrivate::canonicalized(const QString &path) return path; #if defined(Q_OS_UNIX) || defined(Q_OS_SYMBIAN) - // FIXME let's see if this stuff works, then we might be able to remove some of the other code + // FIXME let's see if this stuff works, then we might be able to remove some of the other code. + // baaad Mac: 10.5 and 10.6 crash if trying to free a value returned by + // realpath() if the input path is just the root component. + if (path.size() == 1 && path.at(0) == QLatin1Char('/')) + return path; char *ret = realpath(path.toLocal8Bit().constData(), (char*)0); if (ret) { QString canonicalPath = QDir::cleanPath(QString::fromLocal8Bit(ret)); diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp index 21edbcf..cd58fd6 100644 --- a/tests/auto/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp @@ -513,6 +513,10 @@ void tst_QFileInfo::canonicalFilePath() QFileInfo info("/tmp/../../../../../../../../../../../../../../../../../"); info.canonicalFilePath(); + // This used to crash on Mac + QFileInfo dontCrash(QLatin1String("/")); + QCOMPARE(dontCrash.canonicalFilePath(), QLatin1String("/")); + #ifndef Q_OS_WIN // test symlinks QFile::remove("link.lnk"); -- cgit v0.12