PRB: Memory Allocation Error When Using halloc() or malloc()

ID: Q37201

5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50

MS-DOS                      | WINDOWS
kbprg kbprb

The information in this article applies to:

SYMPTOMS

While running a program you have created with Microsoft C that uses halloc() or malloc(), MS-DOS may print the following message:

   Memory Allocation Error
   Cannot Load COMMAND.COM.

You are able to allocate, use, write, read, and free memory, but when your program finishes, you receive the error.

CAUSE

Your program is probably writing outside of a memory block you allocated using halloc() or malloc(). MS-DOS maintains information about memory usage in blocks immediately preceding the memory given by halloc(). There is also a header following each entry in the heap. The error is usually a result of overwriting these information blocks and headers. The solution is to find out where the program is overwriting memory and correct it.

RESOLUTION

You can determine which part(s) of the program overwrites the memory by using CodeView to set a tracepoint or a breakpoint on the memory in question. If you don't have enough memory to run CodeView, you can narrow down the problem by using a pointer to check those bytes at selected points in your program.

Additional reference words: 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00 KBCategory: kbprg kbprb KBSubcategory: CRTIss Keywords : kb16bitonly

Last Reviewed: July 18, 1997