VirtualBox

Changeset 25552 in vbox


Ignore:
Timestamp:
Dec 21, 2009 8:16:53 PM (15 years ago)
Author:
vboxsync
Message:

lockvalidator.cpp: plugged memory leak.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp

    r25528 r25552  
    473473
    474474/**
    475  * Remove a thread entry from a shared lock record.
     475 * Remove a thread entry from a shared lock record and free it.
    476476 *
    477477 * @param   pShared             The shared lock record.
     
    479479 * @param   iEntry              The last known index.
    480480 */
    481 DECLINLINE(void) rtLockValidatorSharedRecDelete(PRTLOCKVALIDATORSHARED pShared, PRTLOCKVALIDATORSHAREDONE pEntry,
    482                                                 uint32_t iEntry)
    483 {
     481DECLINLINE(void) rtLockValidatorSharedRecRemoveAndFree(PRTLOCKVALIDATORSHARED pShared, PRTLOCKVALIDATORSHAREDONE pEntry,
     482                                                       uint32_t iEntry)
     483{
     484    /*
     485     * Remove it from the table.
     486     */
    484487    rtLockValidatorSerializeDetectionEnter();
    485     if (RT_LIKELY(pShared->u32Magic == RTLOCKVALIDATORSHARED_MAGIC))
    486     {
    487         if (   iEntry >= pShared->cAllocated
    488             || !ASMAtomicCmpXchgPtr((void * volatile *)&pShared->papOwners[iEntry], NULL, pEntry))
    489         {
    490             /* this shouldn't happen yet... */
    491             AssertFailed();
    492             PRTLOCKVALIDATORSHAREDONE volatile *papOwners = pShared->papOwners;
    493             uint32_t const                      cMax      = pShared->cAllocated;
    494             for (iEntry = 0; iEntry < cMax; iEntry++)
    495                 if (ASMAtomicCmpXchgPtr((void * volatile *)&papOwners[iEntry], NULL, pEntry))
    496                    break;
    497             AssertReturnVoidStmt(iEntry < cMax, rtLockValidatorSerializeDetectionLeave());
    498         }
    499         uint32_t cNow = ASMAtomicDecU32(&pShared->cEntries);
    500         Assert(!(cNow & RT_BIT_32(31))); NOREF(cNow);
    501     }
     488    AssertReturnVoidStmt(pShared->u32Magic == RTLOCKVALIDATORSHARED_MAGIC, rtLockValidatorSerializeDetectionLeave());
     489    if (RT_UNLIKELY(   iEntry >= pShared->cAllocated
     490                    || !ASMAtomicCmpXchgPtr((void * volatile *)&pShared->papOwners[iEntry], NULL, pEntry)))
     491    {
     492        /* this shouldn't happen yet... */
     493        AssertFailed();
     494        PRTLOCKVALIDATORSHAREDONE volatile *papOwners = pShared->papOwners;
     495        uint32_t const                      cMax      = pShared->cAllocated;
     496        for (iEntry = 0; iEntry < cMax; iEntry++)
     497            if (ASMAtomicCmpXchgPtr((void * volatile *)&papOwners[iEntry], NULL, pEntry))
     498               break;
     499        AssertReturnVoidStmt(iEntry < cMax, rtLockValidatorSerializeDetectionLeave());
     500    }
     501    uint32_t cNow = ASMAtomicDecU32(&pShared->cEntries);
     502    Assert(!(cNow & RT_BIT_32(31))); NOREF(cNow);
    502503    rtLockValidatorSerializeDetectionLeave();
     504
     505    /*
     506     * Successfully removed, now free it.
     507     */
     508    rtLockValidatorSharedRecFreeThread(pEntry);
    503509}
    504510
     
    564570        pEntry->cRecursion--;
    565571    else
    566         rtLockValidatorSharedRecDelete(pRead, pEntry, iEntry);
     572        rtLockValidatorSharedRecRemoveAndFree(pRead, pEntry, iEntry);
    567573
    568574    return VINF_SUCCESS;
     
    732738    AssertReturnVoid(hThread != NIL_RTTHREAD);
    733739
    734     AssertMsgFailed(("Not implemented"));
     740    /*
     741     * Find the entry hope it's a recursive one.
     742     */
     743    uint32_t iEntry;
     744    PRTLOCKVALIDATORSHAREDONE pEntry = rtLockValidatorSharedRecFindThread(pRead, hThread, &iEntry);
     745    AssertReturnVoid(pEntry);
     746    if (pEntry->cRecursion > 1)
     747        pEntry->cRecursion--;
     748    else
     749        rtLockValidatorSharedRecRemoveAndFree(pRead, pEntry, iEntry);
    735750}
    736751
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