VirtualBox

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


Ignore:
Timestamp:
Jun 1, 2019 12:23:46 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131028
Message:

Devices/DevAHCI: Fix possible memory leak while still maintaining the requirement that the pszDesc parameter passed to PDMDevHlpDriverAttach() needs to be valid over the devices lifetime

File:
1 edited

Legend:

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

    r77183 r78908  
    405405    /** Pointer to the attached driver's extended interface. */
    406406    R3PTRTYPE(PPDMIMEDIAEX)         pDrvMediaEx;
     407    /** Port description. */
     408    R3PTRTYPE(char *)               pszDesc;
    407409    /** The base interface. */
    408410    PDMIBASE                        IBase;
     
    416418    PDMLED                          Led;
    417419
     420#if HC_ARCH_BITS == 64
    418421    uint32_t                        u32Alignment3;
     422#endif
    419423
    420424    /** Async IO Thread. */
     
    24592463     * handling 2nd DWORD failures on split accesses correctly. */
    24602464    int rc = PDMDevHlpMMIORegister(pDevIns, GCPhysAddress, cb, NULL /*pvUser*/,
    2461                                    IOMMMIO_FLAGS_READ_DWORD | IOMMMIO_FLAGS_WRITE_ONLY_DWORD_QWORD,
     2465                                   IOMMMIO_FLAGS_READ_DWORD | IOMMMIO_FLAGS_WRITE_DWORD_QWORD_READ_MISSING,
    24622466                                   ahciMMIOWrite, ahciMMIORead, "AHCI");
    24632467    if (RT_FAILURE(rc))
     
    56865690     * required as well as optional.
    56875691     */
    5688     rc = PDMDevHlpDriverAttach(pDevIns, pAhciPort->iLUN, &pAhciPort->IBase, &pAhciPort->pDrvBase, NULL);
     5692    rc = PDMDevHlpDriverAttach(pDevIns, pAhciPort->iLUN, &pAhciPort->IBase, &pAhciPort->pDrvBase, pAhciPort->pszDesc);
    56895693    if (RT_SUCCESS(rc))
    56905694        rc = ahciR3ConfigureLUN(pDevIns, pAhciPort);
     
    56995703    else
    57005704    {
    5701         char szName[24];
    5702         RTStrPrintf(szName, sizeof(szName), "Port%d", iLUN);
    5703 
    57045705        rc = SUPSemEventCreate(pThis->pSupDrvSession, &pAhciPort->hEvtProcess);
    57055706        if (RT_FAILURE(rc))
     
    57095710        /* Create the async IO thread. */
    57105711        rc = PDMDevHlpThreadCreate(pDevIns, &pAhciPort->pAsyncIOThread, pAhciPort, ahciAsyncIOLoop, ahciAsyncIOLoopWakeUp, 0,
    5711                                    RTTHREADTYPE_IO, szName);
     5712                                   RTTHREADTYPE_IO, pAhciPort->pszDesc);
    57125713        if (RT_FAILURE(rc))
    57135714            return rc;
     
    57175718         */
    57185719        if (RT_SUCCESS(rc))
    5719             rc = ahciR3VpdInit(pDevIns, pAhciPort, szName);
     5720            rc = ahciR3VpdInit(pDevIns, pAhciPort, pAhciPort->pszDesc);
    57205721
    57215722        /* Inform the guest about the added device in case of hotplugging. */
     
    58525853                pAhciPort->hEvtProcess = NIL_SUPSEMEVENT;
    58535854            }
     5855
     5856            if (pAhciPort->pszDesc)
     5857                RTStrFree(pAhciPort->pszDesc);
    58545858        }
    58555859
     
    61136117    for (i = 0; i < pThis->cPortsImpl; i++)
    61146118    {
    6115         char *pszName;
    6116         if (RTStrAPrintf(&pszName, "Port%u", i) <= 0)
     6119        PAHCIPort pAhciPort      = &pThis->ahciPort[i];
     6120
     6121        if (RTStrAPrintf(&pAhciPort->pszDesc, "Port%u", i) <= 0)
    61176122            AssertLogRelFailedReturn(VERR_NO_MEMORY);
    61186123
    6119         PAHCIPort pAhciPort      = &pThis->ahciPort[i];
    61206124        /*
    61216125         * Init interfaces.
     
    61346138
    61356139        /* Query per port configuration options if available. */
    6136         PCFGMNODE pCfgPort = CFGMR3GetChild(pDevIns->pCfg, pszName);
     6140        PCFGMNODE pCfgPort = CFGMR3GetChild(pDevIns->pCfg, pAhciPort->pszDesc);
    61376141        if (pCfgPort)
    61386142        {
     
    61466150         * Attach the block driver
    61476151         */
    6148         rc = PDMDevHlpDriverAttach(pDevIns, pAhciPort->iLUN, &pAhciPort->IBase, &pAhciPort->pDrvBase, pszName);
     6152        rc = PDMDevHlpDriverAttach(pDevIns, pAhciPort->iLUN, &pAhciPort->IBase, &pAhciPort->pDrvBase, pAhciPort->pszDesc);
    61496153        if (RT_SUCCESS(rc))
    61506154        {
     
    61526156            if (RT_FAILURE(rc))
    61536157            {
    6154                 Log(("%s: Failed to configure the %s.\n", __FUNCTION__, pszName));
     6158                Log(("%s: Failed to configure the %s.\n", __FUNCTION__, pAhciPort->pszDesc));
    61556159                return rc;
    61566160            }
     
    61636167             * Init vendor product data.
    61646168             */
    6165             rc = ahciR3VpdInit(pDevIns, pAhciPort, pszName);
     6169            rc = ahciR3VpdInit(pDevIns, pAhciPort, pAhciPort->pszDesc);
    61666170            if (RT_FAILURE(rc))
    61676171                return rc;
     
    61736177
    61746178            rc = PDMDevHlpThreadCreate(pDevIns, &pAhciPort->pAsyncIOThread, pAhciPort, ahciAsyncIOLoop,
    6175                                        ahciAsyncIOLoopWakeUp, 0, RTTHREADTYPE_IO, pszName);
     6179                                       ahciAsyncIOLoopWakeUp, 0, RTTHREADTYPE_IO, pAhciPort->pszDesc);
    61766180            if (RT_FAILURE(rc))
    61776181                return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
    6178                                            N_("AHCI: Failed to create worker thread %s"), pszName);
     6182                                           N_("AHCI: Failed to create worker thread %s"), pAhciPort->pszDesc);
    61796183        }
    61806184        else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
     
    61826186            pAhciPort->pDrvBase = NULL;
    61836187            rc = VINF_SUCCESS;
    6184             LogRel(("AHCI: %s: No driver attached\n", pszName));
     6188            LogRel(("AHCI: %s: No driver attached\n", pAhciPort->pszDesc));
    61856189        }
    61866190        else
    61876191            return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
    6188                                        N_("AHCI: Failed to attach drive to %s"), pszName);
     6192                                       N_("AHCI: Failed to attach drive to %s"), pAhciPort->pszDesc);
    61896193    }
    61906194
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