VirtualBox

Changeset 55752 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
May 8, 2015 12:16:58 PM (10 years ago)
Author:
vboxsync
Message:

Main/cbinding: fix incorrect freeing of string arrays on Windows host, and fix a memory leak in the sample code

Location:
trunk/src/VBox/Main/cbinding
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/cbinding/VBoxCAPI.cpp

    r54027 r55752  
    210210    return S_OK;
    211211#else /* !VBOX_WITH_XPCOM */
     212    VARTYPE vt = VT_UNKNOWN;
     213    HRESULT rc = SafeArrayGetVartype(psa, &vt);
     214    if (FAILED(rc))
     215        return rc;
     216    if (vt == VT_BSTR)
     217    {
     218        /* Special treatment: strings are to be freed explicitly, see sample
     219         * C binding code, so zap it here. No way to reach compatible code
     220         * behavior between COM and XPCOM without this kind of trickery. */
     221        void *pData;
     222        rc = SafeArrayAccessData(psa, &pData);
     223        if (FAILED(rc))
     224            return rc;
     225        ULONG cbElement = VBoxVTElemSize(vt);
     226        if (!cbElement)
     227            return E_INVALIDARG;
     228        Assert(cbElement = psa->cbElements);
     229        ULONG cElements = psa->rgsabound[0].cElements;
     230        memset(pData, '\0', cbElement * cElements);
     231        SafeArrayUnaccessData(psa);
     232    }
    212233    return SafeArrayDestroy(psa);
    213234#endif /* !VBOX_WITH_XPCOM */
  • trunk/src/VBox/Main/cbinding/tstCAPIGlue.c

    r55400 r55752  
    99
    1010/*
    11  * Copyright (C) 2009-2014 Oracle Corporation
     11 * Copyright (C) 2009-2015 Oracle Corporation
    1212 *
    1313 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    756756        ULONG i, cGroups;
    757757        g_pVBoxFuncs->pfnSafeArrayCopyOutParamHelper((void **)&groups, &cbGroups, VT_BSTR, groupsSA);
     758        g_pVBoxFuncs->pfnSafeArrayDestroy(groupsSA);
    758759        cGroups = cbGroups / sizeof(groups[0]);
    759760        for (i = 0; i < cGroups; ++i)
Note: See TracChangeset for help on using the changeset viewer.

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