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:
parent
60ac5957d3
commit
bb5d287cc3
@ -47,7 +47,7 @@ QSharedMemoryPrivate::QSharedMemoryPrivate()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSharedMemoryPrivate::setErrorString(const QString &function)
|
void QSharedMemoryPrivate::setErrorString(QLatin1String function)
|
||||||
{
|
{
|
||||||
Q_UNUSED(function);
|
Q_UNUSED(function);
|
||||||
qWarning() << Q_FUNC_INFO << "Not yet implemented on Android";
|
qWarning() << Q_FUNC_INFO << "Not yet implemented on Android";
|
||||||
|
@ -133,7 +133,7 @@ public:
|
|||||||
bool attach(QSharedMemory::AccessMode mode);
|
bool attach(QSharedMemory::AccessMode mode);
|
||||||
bool detach();
|
bool detach();
|
||||||
|
|
||||||
void setErrorString(const QString &function);
|
void setErrorString(QLatin1String function);
|
||||||
|
|
||||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||||
bool tryLocker(QSharedMemoryLocker *locker, const QString &function) {
|
bool tryLocker(QSharedMemoryLocker *locker, const QString &function) {
|
||||||
|
@ -94,7 +94,7 @@ bool QSharedMemoryPrivate::create(int size)
|
|||||||
#endif
|
#endif
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
const int errorNumber = errno;
|
const int errorNumber = errno;
|
||||||
const QString function = QLatin1String("QSharedMemory::create");
|
const QLatin1String function("QSharedMemory::attach (shm_open)");
|
||||||
switch (errorNumber) {
|
switch (errorNumber) {
|
||||||
case ENAMETOOLONG:
|
case ENAMETOOLONG:
|
||||||
case EINVAL:
|
case EINVAL:
|
||||||
@ -138,7 +138,7 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode)
|
|||||||
#endif
|
#endif
|
||||||
if (hand == -1) {
|
if (hand == -1) {
|
||||||
const int errorNumber = errno;
|
const int errorNumber = errno;
|
||||||
const QString function = QLatin1String("QSharedMemory::attach (shm_open)");
|
const QLatin1String function("QSharedMemory::attach (shm_open)");
|
||||||
switch (errorNumber) {
|
switch (errorNumber) {
|
||||||
case ENAMETOOLONG:
|
case ENAMETOOLONG:
|
||||||
case EINVAL:
|
case EINVAL:
|
||||||
|
@ -149,7 +149,7 @@ bool QSharedMemoryPrivate::create(int size)
|
|||||||
|
|
||||||
// create
|
// create
|
||||||
if (-1 == shmget(unix_key, size, 0600 | IPC_CREAT | IPC_EXCL)) {
|
if (-1 == shmget(unix_key, size, 0600 | IPC_CREAT | IPC_EXCL)) {
|
||||||
QString function = QLatin1String("QSharedMemory::create");
|
const QLatin1String function("QSharedMemory::create");
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case EINVAL:
|
case EINVAL:
|
||||||
errorString = QSharedMemory::tr("%1: system-imposed size restrictions").arg(QLatin1String("QSharedMemory::handle"));
|
errorString = QSharedMemory::tr("%1: system-imposed size restrictions").arg(QLatin1String("QSharedMemory::handle"));
|
||||||
@ -199,7 +199,7 @@ bool QSharedMemoryPrivate::detach()
|
|||||||
{
|
{
|
||||||
// detach from the memory segment
|
// detach from the memory segment
|
||||||
if (-1 == shmdt(memory)) {
|
if (-1 == shmdt(memory)) {
|
||||||
QString function = QLatin1String("QSharedMemory::detach");
|
const QLatin1String function("QSharedMemory::detach");
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case EINVAL:
|
case EINVAL:
|
||||||
errorString = QSharedMemory::tr("%1: not attached").arg(function);
|
errorString = QSharedMemory::tr("%1: not attached").arg(function);
|
||||||
|
@ -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
|
// EINVAL is handled in functions so they can give better error strings
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
|
@ -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)
|
if (windowsError == 0)
|
||||||
return;
|
return;
|
||||||
switch (windowsError) {
|
switch (windowsError) {
|
||||||
@ -91,7 +91,7 @@ void QSharedMemoryPrivate::setErrorString(const QString &function)
|
|||||||
HANDLE QSharedMemoryPrivate::handle()
|
HANDLE QSharedMemoryPrivate::handle()
|
||||||
{
|
{
|
||||||
if (!hand) {
|
if (!hand) {
|
||||||
QString function = QLatin1String("QSharedMemory::handle");
|
const QLatin1String function("QSharedMemory::handle");
|
||||||
if (nativeKey.isEmpty()) {
|
if (nativeKey.isEmpty()) {
|
||||||
error = QSharedMemory::KeyError;
|
error = QSharedMemory::KeyError;
|
||||||
errorString = QSharedMemory::tr("%1: unable to make key").arg(function);
|
errorString = QSharedMemory::tr("%1: unable to make key").arg(function);
|
||||||
@ -130,7 +130,7 @@ bool QSharedMemoryPrivate::cleanHandle()
|
|||||||
|
|
||||||
bool QSharedMemoryPrivate::create(int size)
|
bool QSharedMemoryPrivate::create(int size)
|
||||||
{
|
{
|
||||||
QString function = QLatin1String("QSharedMemory::create");
|
const QLatin1String function("QSharedMemory::create");
|
||||||
if (nativeKey.isEmpty()) {
|
if (nativeKey.isEmpty()) {
|
||||||
error = QSharedMemory::KeyError;
|
error = QSharedMemory::KeyError;
|
||||||
errorString = QSharedMemory::tr("%1: key error").arg(function);
|
errorString = QSharedMemory::tr("%1: key error").arg(function);
|
||||||
|
Loading…
Reference in New Issue
Block a user