VirtualBox

Changeset 102954 in vbox for trunk/src


Ignore:
Timestamp:
Jan 18, 2024 3:32:39 PM (11 months ago)
Author:
vboxsync
Message:

Shared Clipboard/Transfer: Made destroying the transfers easier to use by also free'ing the object within ShClTransferDestroy(). Should also fix the memory leaks within the testcase. bugref:9437

Location:
trunk/src/VBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers.cpp

    r100676 r102954  
    11621162 *
    11631163 * @returns VBox status code.
    1164  * @param   pTransferCtx                Clipboard transfer to destroy.
     1164 * @param   pTransfer           Clipboard transfer to destroy.
     1165 *                              The pointer will be invalid after return.
    11651166 */
    11661167int ShClTransferDestroy(PSHCLTRANSFER pTransfer)
     
    11951196
    11961197    ShClEventSourceDestroy(&pTransfer->Events);
     1198
     1199    RTMemFree(pTransfer);
     1200    pTransfer = NULL;
    11971201
    11981202    LogFlowFuncLeave();
     
    26792683    RTListForEachSafe(&pTransferCtx->List, pTransfer, pTransferNext, SHCLTRANSFER, Node)
    26802684    {
     2685        shclTransferCtxTransferRemoveAndUnregister(pTransferCtx, pTransfer);
    26812686        ShClTransferDestroy(pTransfer);
    2682 
    2683         shclTransferCtxTransferRemoveAndUnregister(pTransferCtx, pTransfer);
    2684 
    2685         RTMemFree(pTransfer);
    2686         pTransfer = NULL;
    26872687    }
    26882688
     
    32353235
    32363236            shclTransferCtxTransferRemoveAndUnregister(pTransferCtx, pTransfer);
    3237 
    32383237            ShClTransferDestroy(pTransfer);
    3239 
    3240             RTMemFree(pTransfer);
    3241             pTransfer = NULL;
    32423238        }
    32433239        else
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-transfers.cpp

    r100667 r102954  
    22932293
    22942294            ShClTransferCtxUnregisterById(pTxCtx, pTransfer->State.uID);
    2295 
    22962295            ShClTransferDestroy(pTransfer);
    2297 
    2298             RTMemFree(pTransfer);
    2299             pTransfer = NULL;
    23002296        }
    23012297    }
     
    23432339
    23442340    if (RT_FAILURE(rc))
    2345     {
    23462341        ShClTransferDestroy(pTransfer);
    2347 
    2348         RTMemFree(pTransfer);
    2349         pTransfer = NULL;
    2350     }
    23512342
    23522343    if (RT_FAILURE(rc))
     
    23832374
    23842375    ShClTransferDestroy(pTransfer);
    2385 
    2386     RTMemFree(pTransfer);
    23872376    pTransfer = NULL;
    23882377
  • trunk/src/VBox/HostServices/SharedClipboard/testcase/tstClipboardTransfers.cpp

    r100641 r102954  
    291291    }
    292292
     293    ShClTransferObjOpenParmsDestroy(&openCreateParms);
     294
    293295    rc = ShClTransferDestroy(pTransfer);
    294296    RTTESTI_CHECK_RC_OK(rc);
     
    310312    ShClEventSourceReset(&Source);
    311313    RTTESTI_CHECK(ShClEventSourceGetLast(&Source) == NULL); /* Event still valid, but removed from the source. */
    312     RTTESTI_CHECK(ShClEventRelease(pEvent) == 0);
    313     RTTESTI_CHECK(ShClEventRelease(pEvent) == UINT32_MAX); /* Ref count already was 0, so returns UINT32_MAX. */
    314     RTTESTI_CHECK(ShClEventRelease(pEvent) == UINT32_MAX); /* Again. */
     314    RTTESTI_CHECK(ShClEventRelease(pEvent) == 0); /* Free'd event, as ref count is 0. */
    315315    RTTESTI_CHECK(ShClEventSourceGetLast(&Source) == NULL); /* Now it should be empty. */
    316316    RTTESTI_CHECK_RC_OK(ShClEventSourceDestroy(&Source));
     
    325325    RTTESTI_CHECK(ShClEventRelease(pEvent) == 1);
    326326    RTTESTI_CHECK(ShClEventGetRefs(pEvent) == 1);
    327     RTTESTI_CHECK(ShClEventRelease(pEvent) == 0); /* Destroys event, as ref count is 0. */
    328     RTTESTI_CHECK(ShClEventRelease(pEvent) == UINT32_MAX);
     327    RTTESTI_CHECK(ShClEventRelease(pEvent) == 0); /* Free'd event, as ref count is 0. */
    329328    RTTESTI_CHECK_RC_OK(ShClEventSourceDestroy(&Source)); /* Try to destruct again. */
    330329}
     
    339338    rc = ShClTransferDestroy(pTransfer);
    340339    RTTESTI_CHECK_RC_OK(rc);
     340    pTransfer = NULL; /* Was free'd above. */
    341341    rc = ShClTransferDestroy(pTransfer); /* Second time, intentional. */
    342342    RTTESTI_CHECK_RC_OK(rc);
     
    354354    ShClTransferListEntryDestroy(&Entry);
    355355    ShClTransferListEntryDestroy(&Entry); /* Second time, intentional. */
     356
     357    rc = ShClTransferDestroy(pTransfer);
     358    RTTESTI_CHECK_RC_OK(rc);
    356359}
    357360
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