This topic is 3691 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everyone! I'm trying to overload the global new and delete for debugging purposes, but something is not working quite right. Today I found what I thought to be a memory leak, but after a more careful debugging session, I think in some cases my overloaded delete just doesn't get called. I'm sure it's crammed full with bugs, so I post some code:
//Prototypes included by the precompiled header
#include <cstddef>

void* operator new ( std::size_t sz ); //Uses std::malloc(sz) internally
void operator delete ( void* ptr ); //Uses STD::free(ptr) internally


The problem seems to be localized here:
void CGigaPaq::m_Dispose() {

}

//PAQ_ITEM* lppiFileList, struct PAQ_ITEM
if (m_lppiFileList) {
delete[] m_lppiFileList;
m_lppiFileList = 0;
}

//CIOFile* m_lpioPaq, class CIOFile
if (m_lpioPaq) {
delete m_lpioPaq;
m_lpioPaq = 0;
}

return;


There Are a few things I don't really understand: either in Visual Studio .net and CodeWarrior, my overloaded version of new is always called (even for arrays). The same is true for delete and delete[], which both seem to call my overloaded delete. But in this special case, neither for m_lppiFileList nor for m_lpioPaq delete gets called. The debugger - instead - takes me to a standard delete function from Visual Studio. Thus the apparent memory leak. I've been searching the net for a while, but I've found nothing that looks like this... Any ideas? Edit: If I actually try to implement overloaded versions for new[] and delete[], I get a multiple definition error: Linking... dlDebugInfo.obj : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in msvcprtd.lib(newaop_s.obj) Debug/DuckLib_Debug.dll : fatal error LNK1169: one or more multiply defined symbols found

##### Share on other sites
I somehow managed to fix the problem. Also, a clean rebuild helped with the multiple inclusion error! :)

1. 1
2. 2
3. 3
frob
15
4. 4
5. 5

• 9
• 20
• 12
• 13
• 14
• ### Forum Statistics

• Total Topics
632143
• Total Posts
3004419

×