Overloading operator new and operator delete

0 Likes

Problem:

I have overloaded operator new and operator delete ANd receive the following message from BoundsChecker

"Memory allocation conflict

Allocated by malloc

Freed by operator delete"

Resolution:

All you need do is 'inform' BoundsChecker that you have overloaded these operators. The way that you do this is to add entries to the ..\data\routine.dat file which is included with BoundsChecker. The entries will consist of your image's public symbol names for your overloaded operator new and delete.

Here are example steps on how to configure this.

1. Configure Visual C to create a .map file. Navigate to the Project | Settings | Link tab | General category and place a check next to the 'Generate map file' checkbox.

2. Set a breakpoint on the curly brace line of your overloaded operator delete function. Later you can do the same for operator new function.

3. Debug your program by hitting F5 key (Build | Start Debug | Go).

4. When the breakpoint gets hit choose to bring up a Disassembly window (View | Debugger Windows | Disassembly). See example Disassembly window contents below. Notice the following line:

004010F0 push ebp

5. Now take this address 004010F0 and search for it in your map file. It will bring you to the following similar line

0001:000000f0 ??3@YAXPAX@Z 004010f0 f yourfile.obj

6. Take note of the public symbol name:

??3@YAXPAX@Z

This is the public symbol name of your overloaded operator delete function. This is part of what you will place in the routine.dat file.

Edit the ..\Data\routine.dat file in a text editor and add the following line:

??3@YAXPAX@Z ID 006

Repeat the same steps for your operator new. You will use the following ID 005 for your operator new. For example, your entries the routine.dat file will be similar to the following:

??_U@YAPAXIPADJ@Z ID 005

??3@YAXPAX@Z ID 006

[Example Disassembly Window]

25: void operator delete(void *_ptr)

26: {

004010F0 push ebp

004010F1 mov ebp,esp

004010F3 sub esp,40h

004010F6 push ebx

004010F7 push esi

004010F8 push edi

004010F9 lea edi,[ebp-40h]

004010FC mov ecx,10h

00401101 mov eax,0CCCCCCCCh

00401106 rep stos dword ptr [edi]

27: free(_ptr);

00401108 mov eax,dword ptr [ebp 8]

0040110B push eax

0040110C call free (00401d10)

00401111 add esp,4

28: }

Old KB# 12100
Comment List
Anonymous
Related Discussions
Recommended