Author Topic: Memory leaks tools  (Read 4594 times)

Silver Hawk

  • Full Member
  • ***
  • Posts: 105
  • Karma: 0
    • View Profile
    • Crestock
Memory leaks tools
« on: February 25, 2006, 12:56:40 PM »
Hello,

Time ago, I was looking for a tool useful for memory leaks detections. Here is the the most interesting ones that i have found. Hope it could be of some help :).

http://www.flipcode.com/articles/article_memoryleaks.shtml
http://www.flipcode.com/cgi-bin/fcarticles.cgi?show=64744
http://www.embedded.com/story/OEG20020321S0021
http://wyw.dcweb.cn/leakage.htm (from http://www.mingw.org/MinGWiki/index.php/FAQ)
http://www.codeproject.com/cpp/MemoryHooks.asp
http://www.codeproject.com/tools/leakfinder.asp
(other links in CodeProject can be found by searching for "Memory leaks")

Best wishes,
Michael

wrt

  • Full Member
  • ***
  • Posts: 139
  • Karma: 0
    • View Profile
Re: Memory leaks tools
« Reply #1 on: February 25, 2006, 02:15:39 PM »
www.valgrind.org can do that too i think

Silver Hawk

  • Full Member
  • ***
  • Posts: 105
  • Karma: 0
    • View Profile
    • Crestock
Re: Memory leaks tools
« Reply #2 on: February 25, 2006, 02:27:54 PM »
www.valgrind.org can do that too i think

Yes, valgrind is good. But, it supports only Linux and not Windows :(. Purify from IBM is good too, but not free :(.

Best wishes,
Michael

sdi

  • Not-a-newbie
  • *
  • Posts: 43
  • Karma: 0
    • View Profile
Re: Memory leaks tools
« Reply #3 on: February 27, 2006, 02:24:29 AM »
Indeed, Purify is amazing  :D. I've used it while we were developing with VC6, but there is no VS2005 support so far  >:(

Silver Hawk

  • Full Member
  • ***
  • Posts: 105
  • Karma: 0
    • View Profile
    • Crestock
Re: Memory leaks tools
« Reply #4 on: February 27, 2006, 04:39:19 AM »
Indeed, Purify is amazing  :D. I've used it while we were developing with VC6, but there is no VS2005 support so far  >:(

Yes, it is a good tool, but relatively complex too and not easy to learn for newbies. I am sure that VS2005 support will come sooner :).

Best wishes,
Michael

Zeuss

  • Not-a-newbie
  • *
  • Posts: 8
  • Karma: 0
    • View Profile
    • Zeussy.com
Re: Memory leaks tools
« Reply #5 on: March 19, 2006, 03:31:56 AM »
here is a modified memory tracker from flipcode.com i have used in my projects:

Code: [Select]
/* <zMemoryTracker.h> Created on 18/03/2006 20:47:50
*
* Description: Memory Leak Finder, orignally from article on flipcode.com Modified a bit by me
* In VS.2003 you have to use /FORCE:MULTIPLE in the linker command line to use it
* Author: Caswal Parker - Copyright 2006
*
*/
#pragma once
#include "stdafx.h"
#ifdef _DEBUG
//Disable some of the warnings damn linker
#pragma warning(disable: 4291)
#pragma warning(disable: 4311)
#pragma warning(disable: 4006)
typedef struct {
DWORD address;
DWORD size;
char file[64];
DWORD line;
} ALLOC_INFO;

typedef std::list<ALLOC_INFO*> AllocList;

AllocList *allocList;

void AddTrack(DWORD addr,  DWORD asize,  const char *fname, DWORD lnum)
{
ALLOC_INFO *info;

if(!allocList) {
allocList = new(AllocList);
}

info = new(ALLOC_INFO);
info->address = addr;
strncpy(info->file, fname, 63);
info->line = lnum;
info->size = asize;
allocList->insert(allocList->begin(), info);
};

void RemoveTrack(DWORD addr)
{
AllocList::iterator i;

if(!allocList)
return;
for(i = allocList->begin(); i != allocList->end(); i++)
{
if((*i)->address == addr)
{
allocList->remove((*i));
break;
}
}
};


void DumpUnfreed()
{
AllocList::iterator i;
DWORD totalSize = 0;
char buf[1024];

if(!allocList)
return;
OutputDebugString("Memory Leaks:\n");
for(i = allocList->begin(); i != allocList->end(); i++) {
sprintf(buf, "%-50s:\t\tLINE %d,\t\tADDRESS %d\t%d bytes unfreed\n",
(*i)->file, (*i)->line, (*i)->address, (*i)->size);
OutputDebugString(buf);
totalSize += (*i)->size;
}
sprintf(buf, "-----------------------------------------------------------\n");
OutputDebugString(buf);
sprintf(buf, "Total Unfreed: %d bytes\n", totalSize);
OutputDebugString(buf);
};




inline void * __cdecl operator new(unsigned int size,
                                    const char *file, int line)
{
void *ptr = (void *)malloc(size);
AddTrack((DWORD)ptr, size, file, line);
return(ptr);
};
inline void __cdecl operator delete(void *p)
{
RemoveTrack((DWORD)p);
free(p);
};
#endif
 


#ifdef _DEBUG
#define DEBUG_NEW new(__FILE__, __LINE__)
#else
#define DEBUG_NEW new
#endif

#define new DEBUG_NEW