How to track memory allocated with my new overloads.



BoundsChecker doesn't see operator new alternatives as new.  This results

in BoundsChecker signalling a malloc/delete type error for situations that

are actually new/delete.


You must add all overloads of new and malloc, etc. to the BoundsChecker routine.dat file.

a) Open the default.all file (using Notepad) in your BoundsChecker\Data directory. This file is located in your BoundsChecker\Data directory and contains the static/public symbols that BC is aware of from the various run-time libraries. Do a search for this line:

"??2@YAPAXI@Z ID  005"

This is the mangled name for the global new. Note the "ID 005". This is the ID BoundsChecker requires to "hook" the new and check it as a memory allocation function. You will also note the multiple versions of "new" below this one --NOTE THEY ALL HAVE "ID 005" NO MATTER WHAT COMPILER THEY COME FROM. This tells BC that even though they are different implementations they are still just a glorified "new".

"??3@YAXPAX@Z ID  006" is the mangled name entry for delete and you will see numerous entries for it also.

Note that the default.all file has this line: "Do not modify this file.  All new entries must be added to your local copy of ROUTINE.DAT."

b) Without an entry for your "new" overload there is no way for BC to "hook" your overload. To add an entry for your "new" open your project in the VC5 or 6 IDE. Make sure you set the Debug build as the Active Configuration. Open Project | Settings and click on the Link tab. Click on "Generate map file". Rebuild your project. Open the .map file in Notepad and you will see all your project's public symbols, etc. Scroll down until you see the entry for your "new". For example, in a default MS implementation, an operator new (std::nothrow) looks like this:

0001:0000a6f0       ??2@YAPAXIABUnothrow_t@std@@@Z 0040b6f0 f   libcpd:newop2.obj

Your overload will have a different .obj and symbol name. You will need to know what .obj contains the your "new" overload. Copy this symbol name to the clipboard ( ??2@YAPAXIABUnothrow_t@std@@@Z  would be the symbol in the above example ).

c)  Open the ROUTINE.DAT file in the BoundsChecker\Data directory. This file is where you put your public\static symbols of which you would like BC aware. After the last semicolon in the file paste your mangled name for your "new". Add the ID 005 after it. Now BC will be aware of your overloaded "new" and will treat it as such. Save the file.

d)  Do the above steps for the overloaded "delete" if there is one adding ID 006.

This process also applies to any other overloads of ANY of the symbols you see in the default.all file.

Old KB# 12261
Comment List
Related Discussions