Fix CreateFileMapping() error handling
CreateFileMapping() returns NULL in case of an error. The patch corrects the wrong testing on INVALID_HANDLE_VALUE, and sets NULL for invalid handles. Change-Id: Iaab4945ed88ee92bbf9a0871e95a5820dd1a56ed Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
This commit is contained in:
parent
f3f6074355
commit
1a8f67938c
@ -128,7 +128,7 @@ void QFSFileEnginePrivate::init()
|
|||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
fileAttrib = INVALID_FILE_ATTRIBUTES;
|
fileAttrib = INVALID_FILE_ATTRIBUTES;
|
||||||
fileHandle = INVALID_HANDLE_VALUE;
|
fileHandle = INVALID_HANDLE_VALUE;
|
||||||
mapHandle = INVALID_HANDLE_VALUE;
|
mapHandle = NULL;
|
||||||
#ifndef Q_OS_WINCE
|
#ifndef Q_OS_WINCE
|
||||||
cachedFd = -1;
|
cachedFd = -1;
|
||||||
#endif
|
#endif
|
||||||
|
@ -900,7 +900,7 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mapHandle == INVALID_HANDLE_VALUE) {
|
if (mapHandle == NULL) {
|
||||||
// get handle to the file
|
// get handle to the file
|
||||||
HANDLE handle = fileHandle;
|
HANDLE handle = fileHandle;
|
||||||
|
|
||||||
@ -933,7 +933,7 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size,
|
|||||||
// first create the file mapping handle
|
// first create the file mapping handle
|
||||||
DWORD protection = (openMode & QIODevice::WriteOnly) ? PAGE_READWRITE : PAGE_READONLY;
|
DWORD protection = (openMode & QIODevice::WriteOnly) ? PAGE_READWRITE : PAGE_READONLY;
|
||||||
mapHandle = ::CreateFileMapping(handle, 0, protection, 0, 0, 0);
|
mapHandle = ::CreateFileMapping(handle, 0, protection, 0, 0, 0);
|
||||||
if (mapHandle == INVALID_HANDLE_VALUE) {
|
if (mapHandle == NULL) {
|
||||||
q->setError(QFile::PermissionsError, qt_error_string());
|
q->setError(QFile::PermissionsError, qt_error_string());
|
||||||
#ifdef Q_USE_DEPRECATED_MAP_API
|
#ifdef Q_USE_DEPRECATED_MAP_API
|
||||||
::CloseHandle(handle);
|
::CloseHandle(handle);
|
||||||
@ -976,6 +976,7 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size,
|
|||||||
}
|
}
|
||||||
|
|
||||||
::CloseHandle(mapHandle);
|
::CloseHandle(mapHandle);
|
||||||
|
mapHandle = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -995,7 +996,7 @@ bool QFSFileEnginePrivate::unmap(uchar *ptr)
|
|||||||
maps.remove(ptr);
|
maps.remove(ptr);
|
||||||
if (maps.isEmpty()) {
|
if (maps.isEmpty()) {
|
||||||
::CloseHandle(mapHandle);
|
::CloseHandle(mapHandle);
|
||||||
mapHandle = INVALID_HANDLE_VALUE;
|
mapHandle = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user