Reactos
1//
2// free.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Implementation of free().
7//
8#include <corecrt_internal.h>
9#include <malloc.h>
10
11// Frees a block in the heap. The 'block' pointer must either be a null pointer
12// or must point to a valid block in the heap.
13//
14// This function supports patching and therefore must be marked noinline.
15// Both _free_dbg and _free_base must also be marked noinline
16// to prevent identical COMDAT folding from substituting calls to free
17// with either other function or vice versa.
18extern "C" _CRT_HYBRIDPATCHABLE __declspec(noinline) void __cdecl free(void* const block)
19{
20 // Some libraries that hook memory allocation routines (such as libtcmalloc)
21 // look for an appropriate place inside free to place a patch to its version
22 // of free. Without these extra instructions padding the call to _free_base,
23 // some libraries may choose to insert this patch in _free_base instead.
24 volatile int extra_instructions_for_patching_libraries = 0;
25 (void) extra_instructions_for_patching_libraries;
26
27 #ifdef _DEBUG
28 _free_dbg(block, _NORMAL_BLOCK);
29 #else
30 _free_base(block);
31 #endif
32}