9 #error This file is supported only in debug builds
27#define _ALLOCATION_FILE_LINENUM "\nMemory allocated at %hs(%d).\n"
29#if _FREE_BLOCK != 0 || _NORMAL_BLOCK != 1 || _CRT_BLOCK != 2 || _IGNORE_BLOCK != 3 || _CLIENT_BLOCK != 4
30 #error Block numbers have changed!
103 "Incorrect debug heap block alignment");
169 return reinterpret_cast<unsigned char*
>(
header + 1);
188 unsigned char const*
const first,
189 unsigned char const value,
194 for (
unsigned char const* it{
first}; it !=
last; ++it)
221 char const* start_address{
static_cast<char const*
>(
p)};
222 char const* end_address {start_address +
size - 1 };
223 if (end_address < start_address)
228 *(
volatile char*)start_address;
232 start_address =
reinterpret_cast<char*
>(
reinterpret_cast<uintptr_t>(start_address) &
mask);
233 end_address =
reinterpret_cast<char*
>(
reinterpret_cast<uintptr_t>(end_address) &
mask);
234 while (start_address != end_address)
236 start_address = start_address +
page_size;
237 *
reinterpret_cast<const volatile char*
>(start_address);
251 unsigned char const*
const possible_alignment_gap{
reinterpret_cast<unsigned char const*
>(
311 void*
block{
nullptr};
343#pragma warning(suppress:__WARNING_UNUSED_ASSIGNMENT)
358 _RPT0(
_CRT_ERROR,
"Error: memory allocation: bad memory block type.\n");
378 header->_block_header_next =
nullptr;
379 header->_block_header_prev =
nullptr;
380 header->_file_name =
nullptr;
413 header->_block_header_prev =
nullptr;
418 header->_request_number = request_number;
541 bool const reallocation_is_allowed
551 if (reallocation_is_allowed && *
new_size == 0)
594 _RPT0(
_CRT_ERROR,
"Error: memory allocation: bad memory block type.\n");
600 _RPTN(
_CRT_ERROR,
"The Block at 0x%p was allocated by aligned routines, use _aligned_realloc()",
block);
618 else if (__acrt_total_allocations < old_head->_data_size)
637 if (reallocation_is_allowed)
639 new_head =
static_cast<_CrtMemBlockHeader*
>(_realloc_base(old_head, new_internal_size));
645 new_head =
static_cast<_CrtMemBlockHeader*
>(_expand_base(old_head, new_internal_size));
664 if (!is_ignore_block)
684 if (*
new_size > new_head->_data_size)
692 if (!is_ignore_block)
696 new_head->_request_number = request_number;
701 _ASSERTE(reallocation_is_allowed || (!reallocation_is_allowed && new_head == old_head));
704 if (new_head == old_head || is_ignore_block)
708 if (new_head->_block_header_next)
710 new_head->_block_header_next->_block_header_prev = new_head->_block_header_prev;
718 if (new_head->_block_header_prev)
856 if (
block ==
nullptr)
859 #if _UCRT_HEAP_MISMATCH_DETECTION && (defined _M_IX86 || defined _M_AMD64)
863 HANDLE const msvcrt_heap_handle = __acrt_get_msvcrt_heap_handle();
864 if (msvcrt_heap_handle)
868 _RPT1(
_CRT_WARN,
"CRTHEAP: ucrt: Attempt to free a pointer (0x%p) that belongs to MSVCRT's private heap, not the process heap.\n",
block);
870 #if _UCRT_HEAP_MISMATCH_BREAK
874 #if _UCRT_HEAP_MISMATCH_RECOVERY
896 _RPTN(
_CRT_ERROR,
"The Block at 0x%p was allocated by aligned routines, use _aligned_free()",
block);
925 _RPTN(
_CRT_ERROR,
"HEAP CORRUPTION DETECTED: before %hs block (#%d) at 0x%p.\n"
926 "CRT detected that the application wrote to memory before start of heap buffer.\n"
936 _RPTN(
_CRT_ERROR,
"HEAP CORRUPTION DETECTED: before %hs block (#%d) at 0x%p.\n"
937 "CRT detected that the application wrote to memory before start of heap buffer.\n",
948 _RPTN(
_CRT_ERROR,
"HEAP CORRUPTION DETECTED: after %hs block (#%d) at 0x%p.\n"
949 "CRT detected that the application wrote to memory after end of heap buffer.\n"
959 _RPTN(
_CRT_ERROR,
"HEAP CORRUPTION DETECTED: after %hs block (#%d) at 0x%p.\n"
960 "CRT detected that the application wrote to memory after end of heap buffer.\n",
987 if (
header->_block_header_next)
989 header->_block_header_next->_block_header_prev =
header->_block_header_prev;
997 if (
header->_block_header_prev)
999 header->_block_header_prev->_block_header_next =
header->_block_header_next;
1098 return old_break_alloc;
1151 bool this_block_okay{
true};
1168 _RPTN(
_CRT_WARN,
"HEAP CORRUPTION DETECTED: before %hs block (#%d) at 0x%p.\n"
1169 "CRT detected that the application wrote to memory before start of heap buffer.\n"
1179 _RPTN(
_CRT_WARN,
"HEAP CORRUPTION DETECTED: before %hs block (#%d) at 0x%p.\n"
1180 "CRT detected that the application wrote to memory before start of heap buffer.\n",
1184 this_block_okay =
false;
1191 _RPTN(
_CRT_WARN,
"HEAP CORRUPTION DETECTED: after %hs block (#%d) at 0x%p.\n"
1192 "CRT detected that the application wrote to memory after end of heap buffer.\n"
1202 _RPTN(
_CRT_WARN,
"HEAP CORRUPTION DETECTED: after %hs block (#%d) at 0x%p.\n"
1203 "CRT detected that the application wrote to memory after end of heap buffer.\n",
1207 this_block_okay =
false;
1215 _RPTN(
_CRT_WARN,
"HEAP CORRUPTION DETECTED: on top of Free block at 0x%p.\n"
1216 "CRT detected that the application wrote to a heap buffer that was freed.\n"
1224 _RPTN(
_CRT_WARN,
"HEAP CORRUPTION DETECTED: on top of Free block at 0x%p.\n"
1225 "CRT detected that the application wrote to a heap buffer that was freed.\n",
1229 this_block_okay =
false;
1232 if (!this_block_okay)
1238 "%hs located at 0x%p is %Iu bytes long.\n"
1253 return this_block_okay;
1263 bool all_okay{
true};
1276 while (trail_it !=
nullptr)
1280 if (trail_it == lead_it)
1283 "Cycle in block list detected while processing block located at 0x%p.\n",
1289 trail_it = trail_it->_block_header_next;
1292 if (lead_it !=
nullptr)
1294 lead_it = lead_it->_block_header_next ==
nullptr
1296 : lead_it->_block_header_next->_block_header_next;
1324 int const valid_flags{
1331 bool const new_bits_have_only_valid_flags = (new_bits & 0xffff & ~valid_flags) == 0;
1365 _CrtDoForAllClientObjectsCallback
const callback,
1395 void const*
const p,
1396 unsigned int const size_in_bytes,
1403 return p !=
nullptr;
1430 void const*
const block,
1431 unsigned const size,
1432 long*
const request_number,
1438 *request_number = 0;
1469 *request_number =
header->_request_number;
1531 state->lCounts[use] = 0;
1532 state->lSizes [use] = 0;
1542 else if (
header->_file_name)
1581 bool significant_difference_found{
false};
1587 if (
state->lSizes[use] == 0 &&
state->lCounts[use] == 0)
1596 significant_difference_found =
true;
1601 state->pBlockHeader =
nullptr;
1603 return significant_difference_found ? 1 : 0;
1614 _LocaleUpdate locale_update{
locale};
1616 static size_t const max_print = 16;
1618 char print_buffer[max_print + 1];
1619 char value_buffer[max_print * 3 + 1];
1622 for (;
i <
min(
header->_data_size, max_print); ++
i)
1626 print_buffer[
i] =
_isprint_l(
c, locale_update.GetLocaleT()) ?
c :
' ';
1630 print_buffer[
i] =
'\0';
1631 _RPTN(
_CRT_WARN,
" Data: <%s> %s\n", print_buffer, value_buffer);
1637 _LocaleUpdate locale_update{
nullptr};
1655 if (
header->_file_name !=
nullptr)
1671 _RPTN(
_CRT_WARN,
"client block at 0x%p, subtype %x, %Iu bytes long.\n",
1695 _RPTN(
_CRT_WARN,
"crt block at 0x%p, subtype %x, %Iu bytes long.\n",
1756 state->lCounts[use],
1783#define IS_2_POW_N(X) ((X) != 0 && ((X) & ((X) - 1)) == 0)
1824 return reinterpret_cast<void*
>(r_ptr);
1863 if (
block ==
nullptr)
1878 _RPTN(
_CRT_ERROR,
"The block at 0x%p was not allocated by _aligned routines, use realloc()",
block);
1914 return (
void *) r_ptr;
1923 size_t header_size = 0;
1924 size_t footer_size = 0;
1925 size_t total_size = 0;
1926 size_t user_size = 0;
1943 user_size = total_size - header_size - footer_size;
1984 _RPTN(
_CRT_ERROR,
"The block at 0x%p was not allocated by _aligned routines, use free()",
block);
_Check_return_ _Ret_maybenull_ _In_ size_t alignment
void __cdecl __acrt_unlock(_In_ __acrt_lock_id lock)
#define _ERRCHECK_SPRINTF(_PrintfCall)
#define _VALIDATE_RETURN_VOID(expr, errorcode)
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
_ACRTIMP void __cdecl _free_base(_Pre_maybenull_ _Post_invalid_ void *_Block)
_Check_return_ _ACRTIMP int __cdecl _callnewh(_In_ size_t _Size)
#define _CrtSetAllocHook(f)
#define _CrtMemDumpAllObjectsSince(s)
void(__cdecl * _CRT_DUMP_CLIENT)(void *, size_t)
#define _realloc_dbg(p, s, t, f, l)
#define _aligned_offset_malloc_dbg(s, a, o, f, l)
#define _CRTDBG_CHECK_ALWAYS_DF
#define _CrtIsValidHeapPointer(p)
#define _aligned_recalloc_dbg(p, c, s, a, f, l)
#define _CrtIsValidPointer(p, n, r)
#define _CRTDBG_CHECK_CRT_DF
#define _CrtDoForAllClientObjects(f, c)
#define _CRTDBG_LEAK_CHECK_DF
#define _CRTDBG_REPORT_FLAG
#define _malloc_dbg(s, t, f, l)
#define _aligned_offset_realloc_dbg(p, s, a, o, f, l)
#define _aligned_realloc_dbg(p, s, a, f, l)
#define _aligned_malloc_dbg(s, a, f, l)
#define _recalloc_dbg(p, c, s, t, f, l)
#define _CrtSetBreakAlloc(a)
#define _RPT0(rptno, msg)
#define _CrtMemDifference(s1, s2, s3)
#define _calloc_dbg(c, s, t, f, l)
#define _aligned_free_dbg(p)
#define _CRTDBG_CHECK_DEFAULT_DF
#define _aligned_offset_recalloc_dbg(p, c, s, a, o, f, l)
#define _CrtSetDbgFlag(f)
#define _CrtSetDumpClient(f)
#define _BLOCK_SUBTYPE(block)
#define _expand_dbg(p, s, t, f, l)
#define _CRTDBG_ALLOC_MEM_DF
#define _CRTDBG_DELAY_FREE_MEM_DF
int(__cdecl * _CRT_ALLOC_HOOK)(int, void *, size_t, int, long, const unsigned char *, int)
#define _CrtIsMemoryBlock(p, t, r, f, l)
#define _RPTN(rptno, msg,...)
#define _CrtMemDumpStatistics(s)
#define _CrtReportBlockType(p)
#define _BLOCK_TYPE(block)
#define _CrtMemCheckpoint(s)
result_buffer_count char *const _In_ int const _In_ bool const _In_ unsigned const _In_ STRFLT const _In_ bool const _Inout_ __crt_cached_ptd_host &ptd throw()
static bool heap_validation_pending
int __cdecl _CrtCheckMemory()
static unsigned char const dead_land_fill
static size_t __acrt_current_allocations
static void __cdecl validate_heap_if_required_nolock()
#define _ALLOCATION_FILE_LINENUM
static unsigned __acrt_check_frequency
static _CrtMemBlockHeader * __acrt_last_block
static void *__cdecl realloc_dbg_nolock(void *const block, size_t *const new_size, int const block_use, char const *const file_name, int const line_number, bool const reallocation_is_allowed)
static long const request_number_for_ignore_blocks
size_t const old_allocation_size
static bool __cdecl is_bad_read_pointer(void const *const p, size_t const size)
static _CrtMemBlockHeader * __acrt_first_block
static void *__cdecl heap_alloc_dbg(size_t const size, int const block_use, char const *const file_name, int const line_number)
static bool __cdecl check_block(_CrtMemBlockHeader *const header)
size_t const allocation_size
int __cdecl _CrtDumpMemoryLeaks()
static long __acrt_current_request_number
_CrtMemBlockHeader *const header
__acrt_lock(__acrt_heap_lock)
int const char const *const file_name
static unsigned __acrt_check_counter
static void __cdecl free_dbg_nolock(void *const block, int const block_use)
size_t const requested_size
static bool __cdecl check_bytes(unsigned char const *const first, unsigned char const value, size_t const size)
static void *__cdecl heap_alloc_dbg_internal(size_t const size, int const block_use, char const *const file_name, int const line_number)
_CRT_ALLOC_HOOK __cdecl _CrtGetAllocHook()
_CRT_DUMP_CLIENT _pfnDumpClient
static size_t const align_gap_size
static char const *const block_use_names[_MAX_BLOCKS]
static bool __cdecl is_block_an_aligned_allocation(void const *const block)
static void __cdecl print_block_data(_locale_t const locale, _CrtMemBlockHeader *const header)
static int const line_number_for_ignore_blocks
int const char const *const int const line_number
static _CrtMemBlockHeader *__cdecl header_from_block(void const *const block)
static unsigned char const align_land_fill
void __cdecl _CrtSetDbgBlockType(void *const block, int const block_use)
static unsigned char const clean_land_fill
static unsigned char const no_mans_land_fill
static size_t __acrt_total_allocations
static size_t const no_mans_land_size
size_t const new_allocation_size
size_t const element_size
static void __cdecl dump_all_object_since_nolock(_CrtMemState const *const state)
_CRT_DUMP_CLIENT __cdecl _CrtGetDumpClient()
static bool __cdecl is_block_type_valid(int const block_use)
long * __p__crtBreakAlloc()
static unsigned char *__cdecl block_from_header(_CrtMemBlockHeader *const header)
static size_t __acrt_max_allocations
_CRT_ALLOC_HOOK _pfnAllocHook
#define HeapFree(x, y, z)
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
void __declspec(noinline) __cdecl _free_base(void *const block)
GLuint GLuint GLsizei count
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
BOOL WINAPI HeapValidate(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem)
#define _isprint_l(_Char, _Locale)
#define EXCEPTION_EXECUTE_HANDLER
#define _VALIDATE_RETURN_NOEXC(expr, errorcode, retexpr)
static DWORD block_size(DWORD block)
#define memcpy(s1, s2, n)
static const struct @1680 read_write[]
static IPrintDialogCallback callback
#define _Analysis_assume_
#define MEMORY_ALLOCATION_ALIGNMENT
#define UNREFERENCED_PARAMETER(P)
_CRTIMP int *__cdecl _errno(void)
unsigned char _gap[align_gap_size]
size_t lCounts[_MAX_BLOCKS]
size_t lSizes[_MAX_BLOCKS]
#define _aligned_msize_dbg(p, a, o)
_ACRTIMP int __cdecl _query_new_mode(void)
SIZE_T WINAPI HeapSize(HANDLE, DWORD, LPCVOID)