Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-27765

QSharedMemory loses the error condition of a failed creation

    XMLWordPrintable

Details

    • bb5d287cc3eb68e1e46e5c3eb0a2c3991900354d

    Description

      QSharedMemoryPrivate::create(int size) on $QTDIR/src/corelib/kernel/qsharedmemory_win.cpp (Qt4.8.3)
      handles wrong return value if sharedmem already exists:

      hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, (wchar_t*)nativeKey.utf16());
      setErrorString(QLatin1String("QSharedMemory::create"));
      
      // hand is valid when it already exists unlike unix so explicitly check
      return !(error == QSharedMemory::AlreadyExists || !hand);
      

      This code does not work right because QLatin1String("QSharedMemory::create") and creating a Qstring when passing
      argument to setErrorString calls malloc() which resets GetLastError(), so setErrorString() does not set
      error to the GetLastError() of CreateFileMapping() but of malloc. This used to work in 4.7.3 as there the
      code did not make the QLatin1String inplace but at the top of the function. The caller
      thinks the shared memory was created by him, even if it already exists and reinits the memory.

      Proposal:

      make a second parameter to setErrorString() as DWORD LastError and every call is made as

      setErrorString(QLatin1String(__FUNCSIG__),GetLastError());
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              andysh Andy Shaw
              qtcomsupport Qt Support
              Votes:
              3 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes