From 73e3d2f6cb002be4ce409c3738db74b61beb12f4 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 17 Oct 2013 11:13:01 +0200 Subject: Windows: Capture last error right after CreateDirectory() in QFileSystemEngine. Custom allocators invoked by freeing the QString contents might change it. Task-number: QTBUG-34046 Task-number: QTBUG-32314 Change-Id: Ied5305c21fcce228448fe565899163997536ea7a Reviewed-by: Joerg Bornemann --- src/corelib/io/qfilesystemengine_win.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index 57231b57a9..257f18a6bb 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -965,8 +965,10 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM return data.hasFlags(what); } -static inline bool mkDir(const QString &path) +static inline bool mkDir(const QString &path, DWORD *lastError = 0) { + if (lastError) + *lastError = 0; #if defined(Q_OS_WINCE) // Unfortunately CreateDirectory returns true for paths longer than // 256, but does not create a directory. It starts to fail, when @@ -986,7 +988,11 @@ static inline bool mkDir(const QString &path) if (platformId == 1 && QFSFileEnginePrivate::longFileName(path).size() > 256) return false; #endif - return ::CreateDirectory((wchar_t*)QFSFileEnginePrivate::longFileName(path).utf16(), 0); + const QString longPath = QFSFileEnginePrivate::longFileName(path); + const bool result = ::CreateDirectory((wchar_t*)longPath.utf16(), 0); + if (lastError) // Capture lastError before any QString is freed since custom allocators might change it. + *lastError = GetLastError(); + return result; } static inline bool rmDir(const QString &path) @@ -1051,9 +1057,9 @@ bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool crea slash = dirName.length(); } if (slash) { + DWORD lastError; QString chunk = dirName.left(slash); - if (!mkDir(chunk)) { - const DWORD lastError = GetLastError(); + if (!mkDir(chunk, &lastError)) { if (lastError == ERROR_ALREADY_EXISTS || lastError == ERROR_ACCESS_DENIED) { bool existed = false; if (isDirPath(chunk, &existed) && existed) -- cgit v1.2.3