00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033
00034 #include <qvaluelist.h>
00035
00036 #define __MEMFILE_C
00037 #include "global.h"
00038
00039 #ifdef _DEBUG
00040
00041 void __cdecl *operator new( unsigned int size, const char *file, int line )
00042 {
00043 void *ptr = (void *)malloc(size);
00044 AddTrack((long)ptr, size, file, line);
00045 return(ptr);
00046 }
00047
00048 void operator delete(void *p)
00049 {
00050 RemoveTrack((long)p);
00051 free(p);
00052 }
00053
00054 #endif
00055
00056
00057 typedef struct {
00058 long address;
00059 long size;
00060 char file[64];
00061 long line;
00062 } ALLOC_INFO;
00063
00064 typedef QValueList<ALLOC_INFO*> AllocList;
00065
00066 AllocList allocList;
00067
00068
00069
00070 void AddTrack(long addr, long asize, const char *fname, long lnum)
00071 {
00072 ALLOC_INFO *info;
00073
00074
00075 info = (ALLOC_INFO *)malloc(sizeof( ALLOC_INFO ));
00076 info->address = addr;
00077 strncpy(info->file, fname, 63);
00078 info->line = lnum;
00079 info->size = asize;
00080 allocList.insert(allocList.begin(), info);
00081 };
00082
00083 void RemoveTrack(long addr)
00084 {
00085 AllocList::Iterator i;
00086
00087 bool found = false;
00088 for(i = allocList.begin(); i != allocList.end(); i++)
00089 {
00090 if((*i)->address == addr)
00091 {
00092 allocList.remove((*i));
00093 found = true;
00094 break;
00095 }
00096 }
00097 }
00098
00099 void DumpUnfreed()
00100 {
00101 AllocList::Iterator i;
00102 long totalSize = 0;
00103 char buf[1024];
00104
00105 for(i = allocList.begin(); i != allocList.end(); i++) {
00106 sprintf(buf, "%-15s: LINE %ld, ADDRESS %ld %ld unfreed",
00107 (*i)->file, (*i)->line, (*i)->address, (*i)->size);
00108 totalSize += (*i)->size;
00109 }
00110 sprintf(buf, "-----------------------------------------------------------\n");
00111 sprintf(buf, "Total Unfreed: %ld bytes\n", totalSize);
00112 };