/* mem.c -- handles: memory allocation and deallocation keeping track of what memory is being used by whom dprintf'ized, 15nov95 */ /* This file is part of the eggdrop source code copyright (c) 1997 Robey Pointer and is distributed according to the GNU general public license. For full details, read the top of 'main.c' or the file called COPYING that was distributed with this code. */ #define LOG_MISC 32 #define MEMTBLSIZE 25000 /* yikes! */ #ifdef EBUG_MEM #define DEBUG #endif #if HAVE_CONFIG_H #include #endif #include #include #include extern int serv; #ifdef DEBUG unsigned long memused=0; static int lastused=0; struct { void *ptr; short size; char file[15]; short line; } memtbl[MEMTBLSIZE]; #endif /* Prototypes */ void mprintf(); void tprintf(); void dprintf(); void putlog(); int expected_memory(); int expmem_chan(); int expmem_chanprog(); int expmem_misc(); int expmem_fileq(); int expmem_users(); int expmem_dccutil(); int expmem_botnet(); int expmem_tcl(); int expmem_tclhash(); int expmem_net(); int expmem_blowfish(); void tell_netdebug(); void debug_blowfish(); /* initialize the memory structure */ void init_mem() { #ifdef DEBUG int i; for (i=0; i60) { sofar[strlen(sofar)-1]=0; if (idx<0) tprintf(-idx,"%s\n",sofar); else dprintf(idx,"%s\n",sofar); strcpy(sofar," "); } } if (sofar[0]) { sofar[strlen(sofar)-1]=0; if (idx<0) tprintf(-idx,"%s\n",sofar); else dprintf(idx,"%s\n",sofar); } } } if (idx<0) tprintf(-idx,"--- End of debug memory list.\n"); else dprintf(idx,"--- End of debug memory list.\n"); #else if (idx<0) tprintf(-idx,"Compiled without debug info.\n"); else dprintf(idx,"Compiled without extensive memory debugging (sorry).\n"); #endif tell_netdebug(idx); debug_blowfish(idx); } void *n_malloc(int size,char *file,int line) { void *x; int i=0; x=(void *)malloc(size); if (x==NULL) { i=i; putlog(LOG_MISC,"*","*** FAILED MALLOC %s (%d)",file,line); return NULL; } #ifdef DEBUG if (lastused==MEMTBLSIZE) { putlog(LOG_MISC,"*","*** MEMORY TABLE FULL: %s (%d)",file,line); return x; } i=lastused; memtbl[i].ptr=x; memtbl[i].line=line; memtbl[i].size=size; strcpy(memtbl[i].file,file); memused+=size; lastused++; #endif return x; } void *n_realloc(void *ptr,int size,char *file,int line) { void *x; int i=0; x=(void *)realloc(ptr,size); if (x==NULL) { i=i; putlog(LOG_MISC,"*","*** FAILED REALLOC %s (%d)",file,line); return NULL; } #ifdef DEBUG for (i=0; (i