Microsoft KB Archive/163370

= You receive a "#File Error#" error message in the place of a file name when you try to call _CrtMemDumpAllObjectsSince to dump the objects on the CRT heap in Visual C++ =

Article ID: 163370

Article Last Modified on 6/2/2005

-

APPLIES TO


 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 4.1 Subscription
 * Microsoft Visual C++ 4.2 Enterprise Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 4.2 Professional Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q163370



SYMPTOMS
When you call _CrtMemDumpAllObjectsSince to dump the objects on the CRT heap, you may see #File Error# in the place of a file name. Following is an example of a dump where both a file name and the #File Error# occurs.

  Dumping objects -> d1.cpp(11) : {27} normal block at 0x007609A0, 222 bytes long. Data: <               > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD   #File Error#(9) : {26} normal block at 0x00760900, 111 bytes long. Data: <               > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD   Object dump complete.



CAUSE
The CRT adds a header to the beginning of every memory block that is allocated. If you have defined the symbol _CRTDBG_MAP_ALLOC before including crtdbg.h, this memory block header contains a pointer to the name of the file where the CRT function that allocated the memory block was called from. #File Error# is emitted instead of the file name when the executing process does not have read access to the memory reference by this pointer.

There are two probable causes for not having read access to the memory reference by this pointer:


 * 1) Heap corruption. Overwriting the block of memory preceding the block giving the #File Error# may have caused corruption in the block header. Usually, there are other errors as well, such as "Damage after Normal Block."
 * 2) The memory block was allocated in a DLL that was unloaded prior to the _CrtMemDumpAllObjectsSince call.



STATUS
This behavior is by design.

Steps to reproduce the behavior
  Type in the following code: // d2.cpp // Create d2.dll by compiling with: CL /LDd /MDd d2.cpp /link /debug #include   #define _CRTDBG_MAP_ALLOC #include   extern "C" _declspec(dllexport) void* a (int cnt) { return malloc(cnt); }

// d1.cpp // Create d1.exe by compiling with: CL /MDd d1.cpp /link d2.lib /debug #include   #include    #define _CRTDBG_MAP_ALLOC #include   void main  { HINSTANCE h = LoadLibrary("d2.dll"); void* (*f)(int) = (void* (*)(int))GetProcAddress(h,"a"); f(111); malloc(222); FreeLibrary(h); _CrtMemDumpAllObjectsSince(0); }                        Create the DLL(d2.dll) and the application(d1.exe). Start Developer Studio with the following command:

MSDEV d1.EXE

Make sure the output window is visible in the Developer Studio.</li> On the Build menu, select Debug and then Go.</li></ol>

Keywords: kberrmsg kbtshoot kbcrt kbprb kbcode KB163370

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.