• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# How To Find Memory Leaks: error

## Recommended Posts

Memory Leak article at flipcode Hey, I have been trying to encorperate this into my code for the past couple hours and have been having a really bad time with it. In the code:
void* operator new(unsigned int size, const char *file, int line)
{
void *ptr = (void *)malloc(size);
return(ptr);
}
I get the oddest errors:  memCheck.cpp memcheck.cpp(7) : error C2059: syntax error : 'string' memcheck.cpp(8) : error C2091: function returns function memcheck.cpp(8) : error C2809: 'operator new' has no formal parameters memcheck.cpp(9) : error C2065: 'size' : undeclared identifier memcheck.cpp(10) : error C2065: 'file' : undeclared identifier memcheck.cpp(10) : error C2065: 'line' : undeclared identifier memcheck.cpp(20) : error C2059: syntax error : 'string' memcheck.cpp(20) : error C2090: function returns array memcheck.cpp(21) : error C2809: 'operator new' has no formal parameters  line 7 is the first line in my example... the decleration part. I am also getting other errors when I use iostrem in the same file:  ......\include\xlocale(218) : error C2660: 'new[]' : function does not take 1 parameters ......\include\xlocnum(53) : see reference to function template instantiation 'char *__cdecl std::_Maklocstr(const char *,char *)' being compiled  I have been trying to work this out for quite some time to no avail, and I was wonderinf if anyone had this problem, or knows what is going on. I can't figure out where my compiler (MSVC++ 6.0) is getting these rediculous errors from... [edited by - Tazzel3d on March 19, 2004 12:28:45 PM]

##### Share on other sites
I did find how to fix my first problem with the wierd errors... It was becaus ethe #defines in the header file were messing with the new key word in my function def:
#ifdef _DEBUG #define DEBUG_NEW new(__FILE__, __LINE__)#else #define DEBUG_NEW new#endif

I am still have problems with stl though. I was able to remove stl from all of my header files, but it is needed in one of my template classes. I can not put the code for the template class anywhere but in the header... which means I need the stl::ostream...

it turns out that even if I try to include memory/memory.h, I get that same error...

any ideas?

Tahnks!

Find out about my diy LCD projector and programming projects!

[edited by - Tazzel3d on March 19, 2004 12:07:33 PM]

##### Share on other sites
Here is a way I know that should work.

void *operator new( size_t size ) {	return malloc(size);}void operator delete( void *pUserData ) {	free(pUserData);}char *myChar = new char[255];

Other than that, if you are still looking for your code to work, do you have string.h included or stdlib?

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

If that still doesn''t work, I have no idea. The way the flipCode code was written I can hardly understand it.

- [BDS]StackOverflow

##### Share on other sites
Hey, thanks for the help. After much frusteration, I finally got it to work after putting the #include "memCheck.h" above every other include in every file. All of the other places I read said that it had to be between standard/stl includes and your includes.

Thanks for the help...

If anything, I hope the next person who runs into this can search and find this thread with the solution.

Dwiel

Find out about my diy LCD projector and programming projects!

##### Share on other sites
here is a much simpler way... just include this in your Stdafx.h file:

#define CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

put this where ever ya want the memory leaks to be shown:

_CrtDumpMemoryLeaks();

##### Share on other sites
Yeah, I got that to work also, but I liked being able to see where and in what file the error came from. It''s also nice to be able to output it to a file so if someone is beta-testing, they can send it to me.

if, you just want a quick''n''dirty checker though, that will work.

Thanks

Dwiel

Find out about my diy LCD projector and programming projects!

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627637
• Total Posts
2978336

• 10
• 12
• 22
• 13
• 33