Welcome! Log In Create A New Profile

Advanced

I've made a code to detect memory leak

Posted by arasium 
I've made a code to detect memory leak
December 02, 2009 05:24PM
Hello everybody,

i've made a little code to detect memory leak and buffer overflow/underflow.

To do that, i've redefined/overwritten malloc, free, memalign and the c++ oprator new, new[], delete and delete[].

You can use this code in c or c++ apps (i use precompiler conditions).

To use this code, you just need to put #include "memoryleak.h" at the beginning of your code files (but after all others include, because it can disturbs stdio.h).
I suggest you to use something like that (to choose if you want to enable or not this capability):

#ifdef MEMORY_LEAK_DEBUG
#include "memoryleak.h"
#endif

To list all allocated pointers, just use the DisplayPointers function.

I've tested that on VC++ and it works (i've used precompiler options to be compatible with gnu and VC compilers).
enjoy:
[www.mediafire.com]



Edited 2 time(s). Last edit at 12/04/2009 05:33PM by arasium.
Re: I've made a code to detect memory leak
December 03, 2009 03:40AM
looks useful. any chance of a english version? i follow most of it, but im sure if i could understand the comments, it would be more useful.



Edited 1 time(s). Last edit at 12/03/2009 03:47AM by giantpune.
Re: I've made a code to detect memory leak
December 03, 2009 01:33PM
Ok ok, i will do that :)
Re: I've made a code to detect memory leak
December 04, 2009 12:25PM
What algorithms does it use? How does it detect buffer overflows? And how are you expecting us to believe that it also does underflow detection?
Re: I've made a code to detect memory leak
December 04, 2009 04:12PM
mmmmh, have you read my source code before asking that?

I've publish the source code, you're free to read it before use it. Why are you so suspicious?

To detect buffer overflow, it is very simple. I've overriden all allocator functions, so when you need memory, i reserved more space than needed (a little aera before to add some info, like the file name where the allocator is called, and a little aera after the buffer).

Then, when you need to delete the object, i check if the aeras are still ok (doing some checksums).


PS: i've some problems with c codes. I think i still need to modifie some structs definitions.
Re: I've made a code to detect memory leak
December 05, 2009 07:04PM
i get errors when using this code. i have a little program i use to rename the devkit and libogc folders on by machine so i can use different versions for different projects. it runs fine without any errors usually. but simply compiling it with your files makes it spit out errors. the only thing the program does is check for folders and rename them and somehow it makes 3 errors.

i admit that i did alter it. i had to add #include to get it to compile. other than that it is untouched.
Re: I've made a code to detect memory leak
December 07, 2009 09:45AM
whar are the errors ?


Because i've also found some errors when i use it with the string class (i don't know why..., perhaps this is due to macro in string header).

I will upload a file i use in my project (it does'nt work if you use the string class). I can compile with that (using the last rev of devkitpro)


Then, i will modify the code to correct this bug.
Re: I've made a code to detect memory leak
December 07, 2009 11:16PM
the errors dont have any specific error with a message to what caused it at all. its just 3 errors. also im not using the string class. the whole code is plain jane c. its just a few char and sprintf()
Re: I've made a code to detect memory leak
December 08, 2009 12:31AM
I think I tested MEMWATCH with an homebrew with no problem. It could be downloaded from: [www.linkdata.se]

You need to add:
#define MEMWATCH
#define MW_STDIO
#include "memwatch/memwatch.h"
You need to add this in your makefile:
-DMEMWATCH -DMEMWATCH_STDIO
Re: I've made a code to detect memory leak
December 09, 2009 10:35AM
giantpune:

ok, the source code of memoryleak is in c++. So, you need to put the two struct definitions in the cpp file. Then use externe "c" {} in the header file to declare the secured function. Then it should be ok.

Thanks Crayon, i will take a look.
Re: I've made a code to detect memory leak
December 10, 2009 05:22AM
May I ask, what your vision for this project? How would you like people to use this project over something like STL and possibly Boost. Is this for only C programmers or C++ also?
Re: I've made a code to detect memory leak
December 10, 2009 09:59AM
It is for C/C++ (you have to adapt it to use it with c projects, i've don't do this, because i only use c++).

Then, it isn't a project. I've done this to identify some bugs in my projects. I only use this code when i want to debug my projects.

Then, you can't compare my code to the STL or Boost. They are framework, but my code is just a little piece of code :) I've given this for people who need something like that. It's just to help. It doesn't matter for me if my code is used or not :)
Re: I've made a code to detect memory leak
December 10, 2009 10:33AM
Thanks for answering so quickly :)
Its nice that you're helping Wiibrew in this way.
Sorry if my questions felt very strong :)
Re: I've made a code to detect memory leak
December 11, 2009 11:36AM
No problem :)
Re: I've made a code to detect memory leak
April 08, 2011 08:04AM
I couldn't understand the comments, it would be more useful if whole code is in English version.
Re: I've made a code to detect memory leak
April 10, 2011 09:19PM
No, it would be more useful if you learned another language.

Maybe a little less arrogance in feeling that everything should be tailored to you.

It would be NICE if there was an English version... not "more useful"

not off to a great start with your first post on the forums...



Edited 1 time(s). Last edit at 04/10/2011 09:20PM by mdbrim.
Sorry, only registered users may post in this forum.

Click here to login