Is there a way to write a memory leak detector supporting new(nothrow)?



Is there a way to write a memory leak detector supporting new(nothrow)?

For example,

#include <My_Debug_New.h>

using namespace std;

int main()
{
int* p1 = new int;
int* p2 = new(nothrow) int; // note this!!!
}

Ideally, after running it in debug mode, owing to p1 and p2 are not
deleted, the output window of the IDE should report memory leaks with
source file names and actual line numbers.

Provided that the whole program doesn't use new(nothrow), I can
implement a memory leak detector as follows:

#if _DEBUG
void* operator new(size_t size, char* srcFileName, int nLineNum);
void* operator delete(void* p);
// ......
#define new new(__FILE__, __LINE__)
#endif

However, by using macro, new and new(nothrow) cannot be simultaneouly
supported. My question is: How to implement this feature that can
simultaneously support? Is this feasible?

Thanks in advance for any help.

.



Relevant Pages

  • Re: How does "new" work in a loop?
    ... freeware program that does this, but it requires all input and output ... My program seems to work fine, but I'm wondering about this loop: ... fsOut.Write(inputBuffer, 0, (int) inputBuffer.Length); ... Unlikely that you are creating a memory leak. ...
    (microsoft.public.dotnet.languages.csharp)
  • [PATCH 1/3] Audit: break up execve argument lists into multiple records
    ... The limit is currently around 7.5k of arguments as userspace ... memory leak on a malloc failure code path. ... making it harder on the kernel to have the memory it needs. ... int audit_n_rules; ...
    (Linux-Kernel)
  • Memory leak problem
    ... After following the advice received in this list, I have isolated the memory leak problem I am having. ... List = initVoiceChannels(List, TempEvent); ... float generateRandomNumber(int intervalA, int intervalB, int incValues) { ... DLLIST *DLCreate(int Tag, void *Object, size_t Size) ...
    (comp.lang.c)
  • Memory Leak Explanation
    ... that Valgrind identifies this program as having a memory leak. ... Linux Mag Code Sample 2003 May ... int main ...
    (alt.comp.lang.learn.c-cpp)