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

Last reviewed: July 17, 1997
Article 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:

  • The C Run-time (CRT), included with:

        - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax
        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.