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 asking for zero bytes
11** with HEAP_ZERO_MEMORY control flag
12**
13**
14**============================================================*/
15#include <palsuite.h>
16
17#define HEAPSIZE 0
18
19int __cdecl main(int argc, char *argv[])
20{
21 int err;
22 HANDLE ProcessHeapHandle;
23 LPVOID lpHeap;
24
25
26 //Initialize the PAL environment
27 err = PAL_Initialize(argc, argv);
28 if(0 != err)
29 {
30 ExitProcess(FAIL);
31 }
32
33 //Retrieve the calling process heap handle
34 ProcessHeapHandle = GetProcessHeap();
35
36 if(!ProcessHeapHandle)
37 {
38 Fail("\nFailed to call GetProcessHeap API!\n");
39 }
40
41 lpHeap = HeapAlloc(ProcessHeapHandle,//HeapHandle
42 HEAP_ZERO_MEMORY,//control flag
43 HEAPSIZE); //specify the heap size
44
45 //lpHeap should be non-NULL pointer
46 if(NULL == lpHeap)
47 {
48 Fail("Failed to call HeapAlloc API, when number of bytes to be allocated is zero!\n");
49 }
50
51 //free the heap memory
52 err = HeapFree(ProcessHeapHandle,
53 0,
54 lpHeap);
55 if(0 == err)
56 {
57 Fail("Failed to call HeapFree API!\n");
58 }
59
60 PAL_Terminate();
61 return PASS;
62}
63