I intercepted the global new/deleteone to catch a memory leak. When the process ends, I need to call assertNoMemoryLeakto bring all the allocated memory to a new one.
But it seems that I cannot make the assertNoMemoryLeaklast function called in my process, because the last global variable destructor will be the last.
atexitdoes not work for the following reason. AFAIK, the global destructor generated by gcc, will be redirected to the list atexitwhen the constructor is called, and I also cannot snippet my push file assertNoMemoryLeak before this at startup, so mine assertNoMemoryLeakwill not be launched as the last function anyway.
Another work around is to write the new/deleteinfo file to a file, and then after the process exits, analyze the file (using a script). I do not want to do it this way, because it is difficult to do this automatically for each developer.
So, any way to make the assertNoMemoryLeaklast function called?
source
share