VirtualBox

Changeset 86386 in vbox


Ignore:
Timestamp:
Oct 1, 2020 2:42:09 PM (4 years ago)
Author:
vboxsync
Message:

IPRT/RTTraceLogRdrDestroy: Free pending events, ignore NIL (iprt protocol) and verify magic. latter applied to other APIs too. bugref:9841

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/log/tracelogreader.cpp

    r85949 r86386  
    5252*   Structures and Typedefs                                                                                                      *
    5353*********************************************************************************************************************************/
    54 
    5554/** Pointer to a trace log reader instance. */
    5655typedef struct RTTRACELOGRDRINT *PRTTRACELOGRDRINT;
     
    102101{
    103102    /** List node for the global list of events. */
    104     RTLISTANCHOR                NdGlob;
     103    RTLISTNODE                  NdGlob;
    105104    /** The trace log reader instance the event belongs to. */
    106105    PRTTRACELOGRDRINT           pRdr;
     
    120119    size_t                      cbEvtData;
    121120    /** Event data, variable in size. */
    122     uint8_t                     abEvtData[1];
     121    RT_FLEXIBLE_ARRAY_EXTENSION
     122    uint8_t                     abEvtData[RT_FLEXIBLE_ARRAY];
    123123} RTTRACELOGRDREVTINT;
    124124/** Pointer to a trace log reader event. */
     
    150150    RTTRACELOGEVTDESC           EvtDesc;
    151151    /** Array of event item descriptors, variable in size. */
    152     RTTRACELOGEVTITEMDESC       aEvtItemDesc[1];
     152    RT_FLEXIBLE_ARRAY_EXTENSION
     153    RTTRACELOGEVTITEMDESC       aEvtItemDesc[RT_FLEXIBLE_ARRAY];
    153154} RTTRACELOGRDREVTDESC;
    154155
     
    179180    /** Pointer to the description if set. */
    180181    const char                  *pszDesc;
    181     /** List of received events. */
     182    /** List of received events (PRTTRACELOGRDREVTINT::NdGlob). */
    182183    RTLISTANCHOR                LstEvts;
    183184    /** Number of event descriptors known. */
     
    10051006                /** @todo Group handling and parenting. */
    10061007
    1007                 pThis->pEvtCur = pEvt;
    10081008                size_t cbEvtDataRecv = pEvtStrm->cRawEvtDataSz * pThis->cbTypeSize + pEvtStrm->cbEvtData;
    10091009                if (cbEvtDataRecv)
     1010                {
     1011                    pThis->pEvtCur = pEvt;
    10101012                    rc = rtTraceLogRdrStateAdvance(pThis, RTTRACELOGRDRSTATE_RECV_EVT_DATA, cbEvtDataRecv);
     1013                }
    10111014                else
    10121015                {
     
    16071610RTDECL(int) RTTraceLogRdrDestroy(RTTRACELOGRDR hTraceLogRdr)
    16081611{
     1612    if (hTraceLogRdr == NIL_RTTRACELOGRDR)
     1613        return VINF_SUCCESS;
    16091614    PRTTRACELOGRDRINT pThis = hTraceLogRdr;
    16101615    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     1616    AssertReturn(pThis->u32Magic == RTTRACELOGRDR_MAGIC, VERR_INVALID_HANDLE);
    16111617
    16121618    pThis->u32Magic = RTTRACELOGRDR_MAGIC_DEAD;
    1613     pThis->pfnStreamClose(pThis->pvUser);
     1619    int rc = pThis->pfnStreamClose(pThis->pvUser);
     1620    AssertRC(rc);
     1621
    16141622    for (unsigned i = 0; i < pThis->cEvtDescsCur; i++)
    16151623        RTMemFree(pThis->papEvtDescs[i]);
    16161624    if (pThis->papEvtDescs)
     1625    {
    16171626        RTMemFree(pThis->papEvtDescs);
     1627        pThis->papEvtDescs = NULL;
     1628    }
     1629
     1630    if (pThis->pEvtCur)
     1631    {
     1632        RTMemFree(pThis->pEvtCur);
     1633        pThis->pEvtCur = NULL;
     1634    }
     1635
     1636    PRTTRACELOGRDREVTINT pCur, pNext;
     1637    RTListForEachSafe(&pThis->LstEvts, pCur, pNext, RTTRACELOGRDREVTINT, NdGlob)
     1638    {
     1639        RTMemFree(pCur);
     1640    }
     1641
    16181642    RTSemMutexDestroy(pThis->hMtx);
     1643    pThis->hMtx = NIL_RTSEMMUTEX;
     1644
    16191645    RTMemFree(pThis->pbScratch);
     1646    pThis->pbScratch = NULL;
     1647
    16201648    RTStrCacheDestroy(pThis->hStrCache);
     1649    pThis->hStrCache = NIL_RTSTRCACHE;
     1650
    16211651    RTMemFree(pThis);
    16221652    return VINF_SUCCESS;
     
    16281658    PRTTRACELOGRDRINT pThis = hTraceLogRdr;
    16291659    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     1660    AssertReturn(pThis->u32Magic == RTTRACELOGRDR_MAGIC, VERR_INVALID_HANDLE);
    16301661    AssertPtrReturn(penmEvt, VERR_INVALID_POINTER);
    16311662
     
    16591690    PRTTRACELOGRDRINT pThis = hTraceLogRdr;
    16601691    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     1692    AssertReturn(pThis->u32Magic == RTTRACELOGRDR_MAGIC, VERR_INVALID_HANDLE);
    16611693    AssertPtrReturn(phRdrEvt, VERR_INVALID_POINTER);
    16621694
     
    16771709    PRTTRACELOGRDRINT pThis = hTraceLogRdr;
    16781710    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     1711    AssertReturn(pThis->u32Magic == RTTRACELOGRDR_MAGIC, VERR_INVALID_HANDLE);
    16791712    AssertPtrReturn(phIt, VERR_INVALID_POINTER);
    16801713
     
    17011734    PRTTRACELOGRDRINT pThis = hTraceLogRdr;
    17021735    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     1736    AssertReturn(pThis->u32Magic == RTTRACELOGRDR_MAGIC, VERR_INVALID_HANDLE);
    17031737    AssertPtrReturn(paMapDesc, VERR_INVALID_PARAMETER);
    17041738    AssertPtrReturn(ppaEvtHdr, VERR_INVALID_POINTER);
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