Q37201: System Memory Allocation Error after Using halloc or malloc
Article: Q37201
Product(s): See article
Version(s): 5.00 5.10
Operating System(s): MS-DOS
Keyword(s): ENDUSER | SR# S880914-27 | mspl13_c
Last Modified: 18-NOV-1988
After running a program you have created that uses malloc or
halloc functions, 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. If you remove halloc()
from your program, it terminates normally.
Your program is probably writing outside of a memory block you
allocated using halloc or malloc. DOS maintains information about
memory usage in blocks immediately preceding the area you're given.
This error is usually are result of overwriting these information
blocks. The solution is to find out where you're overwriting DOS's
memory and avoid doing it.
Note: this error can also be the result of writing PAST the end of a
block because you could corrupt the list entry for the NEXT block.
You can determine where the overwrite occurs by using CodeView to set
a tracepoint on the space after the allocated block. 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.
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.
Copyright Microsoft Corporation 1986-2002.