| 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: test5.c |
| 8 | ** |
| 9 | ** Purpose: Allocate some memory. Then call HeapRealloc with 0 as the |
| 10 | ** amount of memory to reallocate. This should work, essentially freeing |
| 11 | ** the memory (though we can't verfiy this) |
| 12 | ** |
| 13 | ** |
| 14 | **============================================================*/ |
| 15 | |
| 16 | #include <palsuite.h> |
| 17 | |
| 18 | int __cdecl main(int argc, char *argv[]) |
| 19 | { |
| 20 | |
| 21 | HANDLE TheHeap; |
| 22 | char* TheMemory; |
| 23 | char* ReAllocMemory; |
| 24 | char* ReAllocMemory2; |
| 25 | |
| 26 | if(PAL_Initialize(argc, argv) != 0) |
| 27 | { |
| 28 | return FAIL; |
| 29 | } |
| 30 | |
| 31 | TheHeap = GetProcessHeap(); |
| 32 | |
| 33 | if(TheHeap == NULL) |
| 34 | { |
| 35 | Fail("ERROR: GetProcessHeap() returned NULL when it was called. " |
| 36 | "GetLastError() returned %d." ,GetLastError()); |
| 37 | } |
| 38 | |
| 39 | /* Allocate 100 bytes on the heap */ |
| 40 | if((TheMemory = (char*)HeapAlloc(TheHeap, 0, 100)) == NULL) |
| 41 | { |
| 42 | Fail("ERROR: HeapAlloc returned NULL when it was called. " |
| 43 | "GetLastError() returned %d." ,GetLastError()); |
| 44 | } |
| 45 | |
| 46 | /* Set each byte of that memory block to 'x' */ |
| 47 | memset(TheMemory, 'X', 100); |
| 48 | |
| 49 | /* Reallocate the memory into 0 bytes */ |
| 50 | ReAllocMemory = (char*)HeapReAlloc(TheHeap, 0, TheMemory, 0); |
| 51 | |
| 52 | if(ReAllocMemory == NULL) |
| 53 | { |
| 54 | Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of " |
| 55 | "heap memory. GetLastError returns %d." ,GetLastError()); |
| 56 | } |
| 57 | |
| 58 | /* Reallocate the memory we just put into 0 bytes, into 100 bytes. */ |
| 59 | ReAllocMemory2 = (char*)HeapReAlloc(TheHeap, 0, ReAllocMemory, 100); |
| 60 | |
| 61 | if(ReAllocMemory2 == NULL) |
| 62 | { |
| 63 | Fail("ERROR: HeapReAlloc failed to reallocate the 0 bytes of " |
| 64 | "heap memory into 100. GetLastError returns %d." ,GetLastError()); |
| 65 | } |
| 66 | |
| 67 | PAL_Terminate(); |
| 68 | return PASS; |
| 69 | } |
| 70 | |