Reactos
at master 66 lines 1.5 kB view raw
1/* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS DNS Shared Library 4 * FILE: lib/dnslib/memory.c 5 * PURPOSE: DNS Memory Manager Implementation and Heap. 6 */ 7 8/* INCLUDES ******************************************************************/ 9#include "precomp.h" 10 11/* DATA **********************************************************************/ 12 13typedef PVOID 14(WINAPI *PDNS_ALLOC_FUNCTION)(IN SIZE_T Size); 15typedef VOID 16(WINAPI *PDNS_FREE_FUNCTION)(IN PVOID Buffer); 17 18PDNS_ALLOC_FUNCTION pDnsAllocFunction; 19PDNS_FREE_FUNCTION pDnsFreeFunction; 20 21/* FUNCTIONS *****************************************************************/ 22 23VOID 24WINAPI 25Dns_Free(IN PVOID Address) 26{ 27 /* Check if whoever imported us specified a special free function */ 28 if (pDnsFreeFunction) 29 { 30 /* Use it */ 31 pDnsFreeFunction(Address); 32 } 33 else 34 { 35 /* Use our own */ 36 LocalFree(Address); 37 } 38} 39 40PVOID 41WINAPI 42Dns_AllocZero(IN SIZE_T Size) 43{ 44 PVOID Buffer; 45 46 /* Check if whoever imported us specified a special allocation function */ 47 if (pDnsAllocFunction) 48 { 49 /* Use it to allocate the memory */ 50 Buffer = pDnsAllocFunction(Size); 51 if (Buffer) 52 { 53 /* Zero it out */ 54 RtlZeroMemory(Buffer, Size); 55 } 56 } 57 else 58 { 59 /* Use our default */ 60 Buffer = LocalAlloc(LMEM_ZEROINIT, Size); 61 } 62 63 /* Return the allocate pointer */ 64 return Buffer; 65} 66