Windows: Don't cause a malloc before calling GetLastError()

When creating a string it would cause a malloc which would reset
GetLastError() so we need to ensure that GetLastError() is the first thing
it calls if a Windows API call fails.

Task-number: QTBUG-27765
Change-Id: I5cc4ce59aa1f03a0ec978fe54949a7931a225d52
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Andy Shaw 2015-03-16 13:10:27 +01:00
parent 60ac5957d3
commit bb5d287cc3
6 changed files with 11 additions and 11 deletions

View File

@ -47,7 +47,7 @@ QSharedMemoryPrivate::QSharedMemoryPrivate()
{
}
void QSharedMemoryPrivate::setErrorString(const QString &function)
void QSharedMemoryPrivate::setErrorString(QLatin1String function)
{
Q_UNUSED(function);
qWarning() << Q_FUNC_INFO << "Not yet implemented on Android";

View File

@ -133,7 +133,7 @@ public:
bool attach(QSharedMemory::AccessMode mode);
bool detach();
void setErrorString(const QString &function);
void setErrorString(QLatin1String function);
#ifndef QT_NO_SYSTEMSEMAPHORE
bool tryLocker(QSharedMemoryLocker *locker, const QString &function) {

View File

@ -94,7 +94,7 @@ bool QSharedMemoryPrivate::create(int size)
#endif
if (fd == -1) {
const int errorNumber = errno;
const QString function = QLatin1String("QSharedMemory::create");
const QLatin1String function("QSharedMemory::attach (shm_open)");
switch (errorNumber) {
case ENAMETOOLONG:
case EINVAL:
@ -138,7 +138,7 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode)
#endif
if (hand == -1) {
const int errorNumber = errno;
const QString function = QLatin1String("QSharedMemory::attach (shm_open)");
const QLatin1String function("QSharedMemory::attach (shm_open)");
switch (errorNumber) {
case ENAMETOOLONG:
case EINVAL:

View File

@ -149,7 +149,7 @@ bool QSharedMemoryPrivate::create(int size)
// create
if (-1 == shmget(unix_key, size, 0600 | IPC_CREAT | IPC_EXCL)) {
QString function = QLatin1String("QSharedMemory::create");
const QLatin1String function("QSharedMemory::create");
switch (errno) {
case EINVAL:
errorString = QSharedMemory::tr("%1: system-imposed size restrictions").arg(QLatin1String("QSharedMemory::handle"));
@ -199,7 +199,7 @@ bool QSharedMemoryPrivate::detach()
{
// detach from the memory segment
if (-1 == shmdt(memory)) {
QString function = QLatin1String("QSharedMemory::detach");
const QLatin1String function("QSharedMemory::detach");
switch (errno) {
case EINVAL:
errorString = QSharedMemory::tr("%1: not attached").arg(function);

View File

@ -71,7 +71,7 @@ QSharedMemoryPrivate::QSharedMemoryPrivate()
{
}
void QSharedMemoryPrivate::setErrorString(const QString &function)
void QSharedMemoryPrivate::setErrorString(QLatin1String function)
{
// EINVAL is handled in functions so they can give better error strings
switch (errno) {

View File

@ -47,9 +47,9 @@ QSharedMemoryPrivate::QSharedMemoryPrivate() : QObjectPrivate(),
{
}
void QSharedMemoryPrivate::setErrorString(const QString &function)
void QSharedMemoryPrivate::setErrorString(QLatin1String function)
{
BOOL windowsError = GetLastError();
DWORD windowsError = GetLastError();
if (windowsError == 0)
return;
switch (windowsError) {
@ -91,7 +91,7 @@ void QSharedMemoryPrivate::setErrorString(const QString &function)
HANDLE QSharedMemoryPrivate::handle()
{
if (!hand) {
QString function = QLatin1String("QSharedMemory::handle");
const QLatin1String function("QSharedMemory::handle");
if (nativeKey.isEmpty()) {
error = QSharedMemory::KeyError;
errorString = QSharedMemory::tr("%1: unable to make key").arg(function);
@ -130,7 +130,7 @@ bool QSharedMemoryPrivate::cleanHandle()
bool QSharedMemoryPrivate::create(int size)
{
QString function = QLatin1String("QSharedMemory::create");
const QLatin1String function("QSharedMemory::create");
if (nativeKey.isEmpty()) {
error = QSharedMemory::KeyError;
errorString = QSharedMemory::tr("%1: key error").arg(function);