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: heapfree.c
8**
9** Purpose: Positive test the HeapFree API.
10** Call HeapFree to free a memory block
11** and try to free an invalid memory block
12**
13**
14**============================================================*/
15#include <palsuite.h>
16
17#define HEAPSIZE 64
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 if(0 != PAL_Initialize(argc, argv))
28 {
29 return 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
41 lpHeap = HeapAlloc(ProcessHeapHandle,/* HeapHandle */
42 HEAP_ZERO_MEMORY,/* control flag */
43 HEAPSIZE); /* specify the heap size */
44 if(NULL == lpHeap)
45 {
46 Fail("Failed to call HeapAlloc API!\n");
47 }
48
49
50 /* free a allocate heap memory */
51 err = HeapFree(ProcessHeapHandle,
52 0,
53 lpHeap);
54
55 if(0 == err)
56 {
57 Fail("Failed to call HeapFree API!\n");
58 }
59
60 PAL_Terminate();
61 return PASS;
62}
63