 |
|
|
 |
|
|
 |
|
|
I got 9 linker errors. The first one is: nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int,char const *,int)" (??2@YAPAXIPBDH@Z) already defined in tracealloc.obj
Can someone help me?
I'm using VC.NET 2002 with SP1, added tracealloc.cpp only to my project and recompiled. I also added to ignore nafxcwd.lib in Ignore specific library in the Linker
Thanks Garrison
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,Thanks I got this error too. I create a project with VS 2008 , MFC shared dll , unicode. How tell linker that i use the source code function ,replace the dll function?
1>Linking... 1>tracealloc.obj : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in mfc90ud.lib(mfc90ud.dll) 1>tracealloc.obj : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in msvcrtd.lib(MSVCR90D.dll) 1>Build log was saved 1>operator_new_overload_test_mfc - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
You need to force the compiler to accept multiple declarations of a function by setting an argument to the linker as: /FORCE:MULTIPLE. This will make the compiler ignore all subsequent declarations of a function. Just make sure that the linker finds the tracealloc versions of new and delete first.
The instructions for this scenario is described in the sourcecode.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
I am using VC8 and am getting some errors during compile.
memleakfinder\tracealloc.cpp(246) : error C2440: '=' : cannot convert from 'const char *' to 'LPTSTR'
This is also errored on line 258 as well as 246. Any suggestions?
Also, there is an undefined 'i' error at line 547 because of the new scope requirements.
I fixed it with a define at line 545 with a "size_t i;" and removed the define in the for loop:
bool AssertMem(char* m, char c, size_t s) { size_t i; for (i = 0; i < s; i++) if (m[i] != c) break; return i >= s; }
I await your response to the first problem, please...
Regards, David Leikis
|
| Sign In·View Thread·PermaLink | 4.20/5 (2 votes) |
|
|
|
 |
|
|
I fixed the compile errors, but wanted you to know all of the details...
I fixed the LPTSTR error simply by casting the return to:
lpszParamSep = (LPTSTR)_tcschr( lpszParsed, _T(',') );
I hope that this helps.
I will now be trying to use your code. Thank you for your efforts! I hope this helps me find my leaks.
David Leikis
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi
Can you guide me through the step by step procedure of tracking the memory leak....
I am not able to get how to get the memory leak tool to work for working
Can you help me out...
Thanks and Regards Chandrasekar
Chandrasekar
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
If you compile a DLL with the __stdcall calling convention, don't forget to add the __cdecl to the new and delete declarations.
I got this on my debug output:
Memory statistics ----------------- Total allocations: 500 Max concurrent allocations: 43
Does this means I have no leaks?
Thanks for sharing this tool!
Regards, João Paulo Figueira Embedded MVP
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I've solved your problem with detect leaks in dll. At first, you should add this code .... HANDLE g_hSymInitProcess = NULL; .... Then in InitSymInfo tou should add DWORD dwProcessID = GetCurrentProcessId(); g_hSymInitProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
BOOL Res = SymInitialize( g_hSymInitProcess, lpszSymbolPath, TRUE); You cannot use GetCurrentProcess() (see MSDN for SymInitialize) And then replace all GetCurrentProcess() with g_hSymInitProcess In ~cLeakDetector() add CloseHandle(g_hSymInitProcess) After that you should compile dll without exporting any additional functions. And it will detect all memory leak in dll. The same is in execitable.
And I want you to write about how to install debuging tools. I met with this problem and some interesting things. After install debuging tools there is the old version of dll in WinDir\System32. The same after manualy replace dll. So I found that Windows replace dbhhelp.dll if it find that this dll is not native (same for all system dll). So that you should firstly replace dbghelp.dll in dllcache folder and after that in system32 follder.
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
When using the sample project to test the memory leak detector I get no line numbers/file details.
I did some hacking around with tracealloc.cpp. The call stacks its getting in GetStackTrace don't seem to be what I want. The only element in them is always:
ntdll!0x7C90EB94 : KiFastSystemCallRet
Any thoughts?
-Andrew
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
if you change the new operator like this
void* operator new(size_t s) { UINT e = GetLastError(); void *r = TraceAlloc(s); UINT e1 = GetLastError(); return r; }
e will be 0 in my code, but e1 will be 487. It would not affect anything in my programm, but I find it confusing. Took some time to find out, that windows sets this error inside the new operator instead of my own code.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
The TraceAlloc function uses functions from windows that can set raise an error. The errorvalue 487 means: Attempt to access invalid address, ERROR_INVALID_ADDRESS
This is a standard memory accessvoliation but why you get this error I do not know. You'll have to debug to find out where and when this error occurs.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
following is the code void generate_memoryleak(){ new int; // Generate a memory leak } int main(int argc, char** argv){ generate_memoryleak(); return 0; }
but i got the result as Leak of 4 bytes detected: main!0x004012FF : ? main!0x0040134D : ? main!0x004081E9 : ? kernel32!0x77E814C7 : GetCurrentDirectoryW
please help me TIA Binu Jose
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
I am using VC6 with _UNICODE directive. tracealloc.cpp is not compiling because is using macros like va_list that are based on char *.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I don't have access to VC6 anymore but the sample solution above works with UNICODE on VC.NET.
What compiler errors do you get?
|
| Sign In·View Thread·PermaLink | 3.67/5 (2 votes) |
|
|
|
 |
|
|
Those are soe of the errors I am getting:
Compiling... tracealloc.cpp D:\temp\MemLeakFinder\tracealloc.cpp(72) : error C2664: 'vswprintf' : cannot convert parameter 1 from 'char [4096]' to 'unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast D:\temp\MemLeakFinder\tracealloc.cpp(182) : error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast D:\temp\MemLeakFinder\tracealloc.cpp(193) : error C2440: 'initializing' : cannot convert from 'unsigned short [2]' to 'char [4096]' There is no context in which this conversion is possible
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I get something similar if I define only one of _UNICODE and UNICODE. If I define both then the problem goes away.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Hi:
In following situation, Main.exe calls a function in main.dll.
MainExe.cpp vecotr<car> cars; GetInfo(cars)
MainDll.cpp void GetInfo(vector<car> &cars) { cars.push_back( ... ) }
Should i add tracealloc.cpp in both programs? How do I track memory leaks that is in the dll or exe? When I just put traceall.cpp in the exe, it generates an assertion when it tries to free a memory that is allocated in the dll which is not tracked.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Each dll has it's own heap. This makes it harder to track memory. It is not as simple as to add tracealloc.cpp to both dll and exe. The key is to force all allocations into one single dll.
I have made a solution for just this purpose. I will ask the moderators to add it to this article.
It works like this. Add the TraceAlloc.cpp to all of the systems parts (exe and dll's). Add a dependency to MemLeakDll from all system parts as well.
Now you should have a system where all new/delete gets directed to TraceAlloc/TraceDealloc inside MemLeakDll. In other words ALL allocations and deallocations are made inside the MemLeakDll and the problem with different heaps is eliminated.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |