VirtualBox

Changeset 100509 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 11, 2023 11:23:47 AM (20 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
158294
Message:

Shared Clipboard: Resolved a @todo: Use CoTaskMemAlloc() in SharedClipboardWinStreamImpl::Stat(). bugref:9437

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardStreamImpl-win.cpp

    r100507 r100509  
    291291            case STATFLAG_DEFAULT:
    292292            {
    293                 /** @todo r=bird: This is using the wrong allocator.  According to MSDN the
    294                  * caller will pass this to CoTaskMemFree, so we should use CoTaskMemAlloc to
    295                  * allocate it. */
    296                 int rc2 = RTStrToUtf16(m_strPath.c_str(), &pStatStg->pwcsName);
    297                 if (RT_FAILURE(rc2))
    298                     hr = E_FAIL;
     293                size_t const cchLen = m_strPath.length() + 1 /* Include terminator */;
     294                pStatStg->pwcsName = (LPOLESTR)CoTaskMemAlloc(cchLen * sizeof(RTUTF16));
     295                if (pStatStg->pwcsName)
     296                {
     297                    PRTUTF16 pwszStr;
     298                    int rc2 = RTStrToUtf16(m_strPath.c_str(), &pwszStr);
     299                    if (RT_SUCCESS(rc2))
     300                    {
     301                        memcpy(pStatStg->pwcsName, pwszStr, cchLen * sizeof(RTUTF16));
     302                        RTUtf16Free(pwszStr);
     303                        pwszStr = NULL;
     304                    }
     305
     306                    if (RT_FAILURE(rc2))
     307                    {
     308                        CoTaskMemFree(pStatStg->pwcsName);
     309                        pStatStg->pwcsName = NULL;
     310                        hr = E_UNEXPECTED;
     311                    }
     312                }
     313                else
     314                    hr = E_OUTOFMEMORY;
    299315                break;
    300316            }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette