Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.9 KiB

  1. /***
  2. *dbgnew.cpp - defines C++ scalar delete routine, debug version
  3. *
  4. * Copyright (c) 1995-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Defines C++ scalar delete() routine.
  8. *
  9. *Revision History:
  10. * 12-28-95 JWM Split from dbgnew.cpp for granularity.
  11. * 05-22-98 JWM Support for KFrei's RTC work, and operator delete[].
  12. * 07-28-98 JWM RTC update.
  13. * 05-26-99 KBF Updated RTC_Allocate_hook params
  14. * 10-21-99 PML Get rid of delete[], use heap\delete2.cpp for both
  15. * debug and release builds (vs7#53440).
  16. * 04-29-02 GB Added try-finally arounds lock-unlock.
  17. *
  18. *******************************************************************************/
  19. #ifdef _DEBUG
  20. #include <cruntime.h>
  21. #include <malloc.h>
  22. #include <mtdll.h>
  23. #include <dbgint.h>
  24. #include <rtcsup.h>
  25. /***
  26. *void operator delete() - delete a block in the debug heap
  27. *
  28. *Purpose:
  29. * Deletes any type of block.
  30. *
  31. *Entry:
  32. * void *pUserData - pointer to a (user portion) of memory block in the
  33. * debug heap
  34. *
  35. *Return:
  36. * <void>
  37. *
  38. *******************************************************************************/
  39. void operator delete(
  40. void *pUserData
  41. )
  42. {
  43. _CrtMemBlockHeader * pHead;
  44. RTCCALLBACK(_RTC_Free_hook, (pUserData, 0));
  45. if (pUserData == NULL)
  46. return;
  47. _mlock(_HEAP_LOCK); /* block other threads */
  48. __TRY
  49. /* get a pointer to memory block header */
  50. pHead = pHdr(pUserData);
  51. /* verify block type */
  52. _ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));
  53. _free_dbg( pUserData, pHead->nBlockUse );
  54. __FINALLY
  55. _munlock(_HEAP_LOCK); /* release other threads */
  56. __END_TRY_FINALLY
  57. return;
  58. }
  59. #endif /* _DEBUG */