VirtualBox

Changeset 83587 in vbox for trunk/src/VBox/Devices/Storage


Ignore:
Timestamp:
Apr 6, 2020 12:31:32 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
136946
Message:

Virtio_1_0: Reworked the VIRTIO_DESC_CHAIN_T handling to decrease the potential for memory leaks by employing reference counting and not having virtioCoreR3QueuePut be the one to free/release the chain. Combined the 5 allocations into a single one. bugref:9440

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DevVirtioSCSI.cpp

    r83582 r83587  
    717717    }
    718718
    719     PVIRTIO_DESC_CHAIN_T pDescChain;
     719    PVIRTIO_DESC_CHAIN_T pDescChain = NULL;
    720720    int rc = virtioCoreR3QueueGet(pDevIns, &pThis->Virtio, EVENTQ_IDX, &pDescChain, true);
    721721    AssertRCReturn(rc, rc);
     
    742742    virtioCoreR3QueuePut(pDevIns, &pThis->Virtio, EVENTQ_IDX, &ReqSgBuf, pDescChain, true /*fFence*/);
    743743    virtioCoreQueueSync(pDevIns, &pThis->Virtio, EVENTQ_IDX);
     744    virtioCoreR3DescChainRelease(pDescChain);
    744745
    745746    return VINF_SUCCESS;
     
    751752    RTMemFree(pReq->pbSense);
    752753    pReq->pbSense = NULL;
     754    virtioCoreR3DescChainRelease(pReq->pDescChain);
     755    pReq->pDescChain = NULL;
    753756    pTarget->pDrvMediaEx->pfnIoReqFree(pTarget->pDrvMediaEx, pReq->hIoReq);
    754757}
     
    12571260    pReq->cbDataOut   = cbDataOut;
    12581261    pReq->pDescChain  = pDescChain;
     1262    virtioCoreR3DescChainRetain(pDescChain); /* (For pReq->pDescChain. Released by virtioScsiR3FreeReq.) */
    12591263    pReq->uDataInOff  = offDataIn;
    12601264    pReq->uDataOutOff = offDataOut;
     
    15501554                                                    pWorkerR3->auRedoDescs[i], &pDescChain);
    15511555                  if (RT_FAILURE(rc))
    1552                      LogRel(("Error fetching desc chain to redo, %Rrc", rc));
     1556                      LogRel(("Error fetching desc chain to redo, %Rrc", rc));
    15531557
    15541558                  rc = virtioScsiR3ReqSubmit(pDevIns, pThis, pThisCC, qIdx, pDescChain);
    15551559                  if (RT_FAILURE(rc))
    1556                      LogRel(("Error submitting req packet, resetting %Rrc", rc));
     1560                      LogRel(("Error submitting req packet, resetting %Rrc", rc));
     1561
     1562                  virtioCoreR3DescChainRelease(pDescChain);
    15571563             }
    15581564             pWorkerR3->cRedoDescs = 0;
    15591565
    15601566             Log6Func(("fetching next descriptor chain from %s\n", VIRTQNAME(qIdx)));
    1561              PVIRTIO_DESC_CHAIN_T pDescChain;
     1567             PVIRTIO_DESC_CHAIN_T pDescChain = NULL;
    15621568             int rc = virtioCoreR3QueueGet(pDevIns, &pThis->Virtio, qIdx, &pDescChain, true);
    15631569             if (rc == VERR_NOT_AVAILABLE)
    15641570             {
    1565                 Log6Func(("Nothing found in %s\n", VIRTQNAME(qIdx)));
    1566                 continue;
     1571                 Log6Func(("Nothing found in %s\n", VIRTQNAME(qIdx)));
     1572                 continue;
    15671573             }
    15681574
     
    15721578             else /* request queue index */
    15731579             {
    1574                   rc = virtioScsiR3ReqSubmit(pDevIns, pThis, pThisCC, qIdx, pDescChain);
    1575                   if (RT_FAILURE(rc))
    1576                       LogRel(("Error submitting req packet, resetting %Rrc", rc));
     1580                 rc = virtioScsiR3ReqSubmit(pDevIns, pThis, pThisCC, qIdx, pDescChain);
     1581                 if (RT_FAILURE(rc))
     1582                     LogRel(("Error submitting req packet, resetting %Rrc", rc));
    15771583             }
     1584
     1585             virtioCoreR3DescChainRelease(pDescChain);
    15781586        }
    15791587    }
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