| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | /*============================================================= |
| 6 | ** |
| 7 | ** Source: heapalloc.c |
| 8 | ** |
| 9 | ** Purpose: Positive test the HeapAlloc API. |
| 10 | ** Call HeapAlloc with HEAP_ZERO_MEMORY control flag |
| 11 | ** |
| 12 | ** |
| 13 | **============================================================*/ |
| 14 | #include <palsuite.h> |
| 15 | |
| 16 | #define HEAPSIZE 64 |
| 17 | |
| 18 | int __cdecl main(int argc, char *argv[]) |
| 19 | { |
| 20 | int err; |
| 21 | HANDLE ProcessHeapHandle; |
| 22 | LPVOID lpHeap; |
| 23 | |
| 24 | |
| 25 | //Initialize the PAL environment |
| 26 | err = PAL_Initialize(argc, argv); |
| 27 | if(0 != err) |
| 28 | { |
| 29 | ExitProcess(FAIL); |
| 30 | } |
| 31 | |
| 32 | //Retrieve the calling process heap handle |
| 33 | ProcessHeapHandle = GetProcessHeap(); |
| 34 | |
| 35 | if(!ProcessHeapHandle) |
| 36 | { |
| 37 | Fail("\nFailed to call GetProcessHeap API!\n" ); |
| 38 | } |
| 39 | |
| 40 | lpHeap = HeapAlloc(ProcessHeapHandle,//HeapHandle |
| 41 | HEAP_ZERO_MEMORY,//control flag |
| 42 | HEAPSIZE); //specify the heap size |
| 43 | if(NULL == lpHeap) |
| 44 | { |
| 45 | Fail("Failed to call HeapAlloc API!\n" ); |
| 46 | } |
| 47 | |
| 48 | //free the heap memory |
| 49 | err = HeapFree(ProcessHeapHandle, |
| 50 | 0, |
| 51 | lpHeap); |
| 52 | if(0 == err) |
| 53 | { |
| 54 | Fail("Failed to call HeapFree API!\n" ); |
| 55 | } |
| 56 | |
| 57 | PAL_Terminate(); |
| 58 | return PASS; |
| 59 | } |
| 60 | |