From d705b62141d092a5a9ca4e905bab2d1f1a1c3e9e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 Jan 2000 03:31:41 +0000 Subject: got rid of mem_man yamd is much better, and doesn't require any source code changes if you haven't seen yamd then take a look at http://www3.hmc.edu/~neldredge/yamd/ its excellent! (This used to be commit 25b13f8b79d648188036f027f45bc78ec117cc88) --- source3/include/includes.h | 4 - source3/lib/util.c | 7 - source3/mem_man/mem_man.c | 742 ------------------------------------------ source3/mem_man/mem_man.h | 92 ------ source3/nmbd/nmbd.c | 2 - source3/rpcclient/rpcclient.c | 8 - source3/smbd/server.c | 2 - 7 files changed, 857 deletions(-) delete mode 100644 source3/mem_man/mem_man.c delete mode 100644 source3/mem_man/mem_man.h diff --git a/source3/include/includes.h b/source3/include/includes.h index 3fcec98f32..3e9010bf54 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -128,13 +128,9 @@ #include #endif -#ifdef MEM_MAN -#include "../mem_man/mem_man.h" -#else #ifdef HAVE_MALLOC_H #include #endif -#endif #ifdef HAVE_FCNTL_H #include diff --git a/source3/lib/util.c b/source3/lib/util.c index d3a63691df..0ad14ad3ae 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1716,13 +1716,6 @@ void *Realloc(void *p,size_t size) else ret = (void *)realloc(p,size); -#ifdef MEM_MAN - { - extern FILE *dbf; - smb_mem_write_info(ret, dbf); - } -#endif - if (!ret) DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size)); diff --git a/source3/mem_man/mem_man.c b/source3/mem_man/mem_man.c deleted file mode 100644 index 758fac4386..0000000000 --- a/source3/mem_man/mem_man.c +++ /dev/null @@ -1,742 +0,0 @@ -#if MEM_MAN -/* a simple memory manager. All allocates and frees should go through here */ - -#include -#include -#include -#include - -#define MEM_MAN_MAIN - -#include "mem_man.h" - -#ifdef MEM_SIGNAL_HANDLER -#include -#endif - -/* - this module is stand alone. typically a define will occur in a C file - like this - - #define malloc(x) smb_mem_malloc(x,__FILE__,__LINE__) - #define free(x) smb_mem_free(x,__FILE__,__LINE__) - - which redirects all calls to malloc and free through this module - - Various configuration options can be set in mem_man.h. This file also - includes the defines above - so the complete system can be implemented - with just one include call. - - - */ - -extern FILE *dbf; - -/* - ACCESSING the memory manager : - - mem_init_memory_manager() : - initialises internal data structures of memory manager - - void *malloc(size_t size) : - allocates memory as per usual. also records lots of info - - int free(void *ptr) : - frees some memory as per usual. writes errors if necessary. - - void *smb_mem_resize(void *ptr,size_t newsize) : - changes the memory assignment size of a pointer. note it may return a - different pointer than the one given. memory can be sized up or down. - - int smb_mem_query_size(void *ptr) : - returns the size of the allocated memory. - - int smb_mem_query_real_size(void *ptr) : - returns the actual amount of memory allocated to a pointer. - - char *smb_mem_query_file(void *ptr) : - returns the name of the file where the pointer was allocated. - - int smb_mem_query_line(void *ptr) : - returns the line of the file where the memory was allocated. - - void smb_mem_write_status(FILE *outfile) : - writes short summary of memory stats on the stream. - - void smb_mem_write_verbose(FILE *outfile) : - writes lots of info on current allocations to stream. - - void smb_mem_write_errors(FILE *outfile) : - writes info on error blocks - - void smb_mem_write_info(void *ptr,FILE *outfile) - writes info on one pointer to outfile - - int smb_mem_test(void *ptr) : - returns true if the pointer is OK - false if it is not. - - void smb_mem_set_multiplier(int multiplier) : - sets defaults amount of memory allocated to multiplier times - amount requested. - - int smb_mem_total_errors(void) : - returns the total number of error blocks - - void smb_mem_check_buffers(void) : - checks all buffers for corruption. It marks them as corrupt if they are. - - kill -USR1 : - this will send a signal to the memory manager to do a mem_write_verbose - it also checks them for corruption. Note that the signal number can be - set in the header file mem_man.h. This can also be turned off. - - */ - - -void smb_mem_write_errors(FILE *outfile); -void smb_mem_write_verbose(FILE *outfile); -void smb_mem_write_status(FILE *outfile); -static void mem_check_buffers(void); - - -#define FREE_FAILURE 0 -#define FREE_SUCCESS 1 -#define FN -#define True (0==0) -#define False (!True) -#define BUF_SIZE (MEM_CORRUPT_BUFFER * sizeof(char) * 2) -#define BUF_OFFSET (BUF_SIZE/2) - -typedef struct -{ - void *pointer; - size_t present_size; - size_t allocated_size; - unsigned char status; - short error_number; - char file[MEM_FILE_STR_LENGTH]; - unsigned short line; -} memory_struct; - -/* the order of this enum is important. everything greater than - S_ALLOCATED is considered an error */ -enum status_types {S_UNALLOCATED,S_ALLOCATED, - S_ERROR_UNALLOCATED,S_ERROR_FREEING, - S_CORRUPT_FRONT,S_CORRUPT_BACK,S_CORRUPT_FRONT_BACK}; - -/* here is the data memory */ - -static memory_struct *memory_blocks=NULL; /* these hold the allocation data */ -static int mem_blocks_allocated=0; /* how many mem blocks are allocated */ -static int mem_multiplier; /* this is the current multiplier mor over allocation */ -static int mem_manager_initialised=False; /* has it been initialised ? */ -static int last_block_allocated=0; /* a speed up method - this will contain the - index of the last block allocated or freed - to cut down searching time for a new block */ - - -typedef struct -{ - int status; - char *label; -} stat_str_type; - -static stat_str_type stat_str_struct[] = -{ -{S_UNALLOCATED,"S_UNALLOCATED"}, -{S_ALLOCATED,"S_ALLOCATED"}, -{S_ERROR_UNALLOCATED,"S_ERROR_UNALLOCATED"}, -{S_ERROR_FREEING,"S_ERROR_FREEING"}, -{S_CORRUPT_FRONT,"S_CORRUPT_FRONT"}, -{S_CORRUPT_BACK,"S_CORRUPT_BACK"}, -{S_CORRUPT_FRONT_BACK,"S_CORRUPT_FRONT_BACK"}, -{-1,NULL} -}; - - -#define INIT_MANAGER() if (!mem_manager_initialised) mem_init_memory_manager() - -/******************************************************************* - returns a pointer to a static string for each status - ********************************************************************/ -static char *status_to_str(int status) -{ - int i=0; - while (stat_str_struct[i].label != NULL) - { - if (stat_str_struct[i].status == status) - return(stat_str_struct[i].label); - i++; - } - return(NULL); -} - - - -#ifdef MEM_SIGNAL_HANDLER -/******************************************************************* - this handles signals - causes a mem_write_verbose on stderr - ********************************************************************/ -static void mem_signal_handler() -{ - mem_check_buffers(); - smb_mem_write_verbose(dbf); - signal(MEM_SIGNAL_VECTOR,mem_signal_handler); -} -#endif - -#ifdef MEM_SIGNAL_HANDLER -/******************************************************************* - this handles error signals - causes a mem_write_verbose on stderr - ********************************************************************/ -static void error_signal_handler() -{ - fprintf(dbf,"Received error signal!\n"); - mem_check_buffers(); - smb_mem_write_status(dbf); - smb_mem_write_errors(dbf); - abort(); -} -#endif - - -/******************************************************************* - initialise memory manager data structures - ********************************************************************/ -static void mem_init_memory_manager(void) -{ - int i; - /* allocate the memory_blocks array */ - mem_blocks_allocated = MEM_MAX_MEM_OBJECTS; - - while (mem_blocks_allocated > 0) - { - memory_blocks = (memory_struct *) - calloc(mem_blocks_allocated,sizeof(memory_struct)); - if (memory_blocks != NULL) break; - mem_blocks_allocated /= 2; - } - - if (memory_blocks == NULL) - { - fprintf(dbf,"Panic ! can't allocate mem manager blocks!\n"); - abort(); - } - - /* just loop setting status flag to unallocated */ - for (i=0;i mem_blocks_allocated-1) start = mem_blocks_allocated-1; - for (i=start;i>=0;i--) - if ((memory_blocks[i].status == S_ALLOCATED) && - (memory_blocks[i].pointer == ptr)) - return(i); - for (i=(start+1);i ((int)S_ALLOCATED)) - mem_write_Index_info(Index,outfile); -} - - -/******************************************************************* - sets the memory multiplier - ********************************************************************/ -void smb_mem_set_multiplier(int multiplier) -{ - /* check it is valid */ - if (multiplier < 1) return; - mem_multiplier = multiplier; -} - -/******************************************************************* - increases or decreases the memory assigned to a pointer - ********************************************************************/ -void *smb_mem_resize(void *ptr,size_t newsize) -{ - int Index; - size_t allocsize; - void *temp_ptr; - INIT_MANAGER(); - Index = mem_find_Index(ptr); - - /* if invalid return NULL */ - if (Index<0) - { -#ifdef BUG - int Error(); - Error("Invalid mem_resize to size %d\n",newsize); -#endif - return(NULL); - } - - /* now - will it fit in the current allocation ? */ - if (newsize <= memory_blocks[Index].allocated_size) - { - memory_blocks[Index].present_size = newsize; - mem_fill_buffer(Index); - return(ptr); - } - - /* can it be allocated ? */ - allocsize = newsize*mem_multiplier; - temp_ptr = malloc(newsize*mem_multiplier + BUF_SIZE); - - /* no? try with just the size asked for */ - if (temp_ptr == NULL) - { - allocsize=newsize; - temp_ptr = malloc(newsize + BUF_SIZE); - } - - /* if it's still NULL give up */ - if (temp_ptr == NULL) - return(NULL); - - /* copy the old data to the new memory area */ - memcpy(temp_ptr,(char *)memory_blocks[Index].pointer - BUF_OFFSET, - memory_blocks[Index].allocated_size + BUF_SIZE); - - /* fill the extra space */ - mem_fill_bytes((char *)temp_ptr + BUF_OFFSET + memory_blocks[Index].present_size,newsize - memory_blocks[Index].present_size,Index); - - - /* free the old mem and set vars */ - free((char *)ptr - BUF_OFFSET); - memory_blocks[Index].pointer = (void *)((char *)temp_ptr + BUF_OFFSET); - memory_blocks[Index].present_size = newsize; - memory_blocks[Index].allocated_size = allocsize; - - /* fill the buffer appropriately */ - mem_fill_buffer(Index); - - - /* now return the new pointer */ - return((char *)temp_ptr + BUF_OFFSET); -} - -#else - void dummy_mem_man(void) {} -#endif diff --git a/source3/mem_man/mem_man.h b/source3/mem_man/mem_man.h deleted file mode 100644 index 60e31e6d44..0000000000 --- a/source3/mem_man/mem_man.h +++ /dev/null @@ -1,92 +0,0 @@ -#if (defined(NOMEMMAN) && !defined(MEM_MAN_MAIN)) -#include -#else - -/* user settable parameters */ - -#define MEM_MANAGER - -/* -this is the maximum number of blocks that can be allocated at one -time. Set this to more than the max number of mallocs you want possible -*/ -#define MEM_MAX_MEM_OBJECTS 20000 - -/* -maximum length of a file name. This is for the source files only. This -would normally be around 30 - increase it only if necessary -*/ -#define MEM_FILE_STR_LENGTH 30 - -/* -default mem multiplier. All memory requests will be multiplied by -this number, thus allowing fast resizing. High values chew lots of -memory but allow for easy resizing -*/ -#define MEM_DEFAULT_MEM_MULTIPLIER 1 - -/* -the length of the corruption buffers before and after each memory block. -Using these can reduce memory overrun errors and catch bad code. The -amount actually allocated is this times 2 times sizeof(char) -*/ -#define MEM_CORRUPT_BUFFER 16 - -/* -the 'seed' to use for the corruption buffer. zero is a very bad choice -*/ -#define MEM_CORRUPT_SEED 0x10 - - -/* -seed increment. This is another precaution. This will be added to the -'seed' for each adjacent element of the corruption buffer -*/ -#define MEM_SEED_INCREMENT 0x1 - - -/* -memory fill. This will be copied over all allocated memory - to aid in -debugging memory dumps. It is one byte long -*/ -#define MEM_FILL_BYTE 42 - - -/* -this determines whether free() on your system returns an integer or -nothing. If unsure then leave this un defined. -*/ -/* #define MEM_FREE_RETURNS_INT */ - - -/* - This determines whether a signal handler will be instelled to do - a mem_write_verbose on request -*/ -#define MEM_SIGNAL_HANDLER - - -/* -This sets which vector to use if MEM_SIGNAL_HANDLER is defined -*/ -#define MEM_SIGNAL_VECTOR SIGUSR1 - -#ifndef MEM_MAN_MAIN -#ifdef malloc -# undef malloc -#endif -#define malloc(x) smb_mem_malloc(x,__FILE__,__LINE__) -#define free(x) smb_mem_free(x,__FILE__,__LINE__) -#define realloc(ptr,newsize) smb_mem_resize(ptr,newsize) -#ifdef calloc -# undef calloc -#endif -#define calloc(nitems,size) malloc(((_mem_size)nitems)*((_mem_size)size)) - -#ifdef strdup -# undef strdup -#endif -#define strdup(s) smb_mem_strdup(s, __FILE__, __LINE__) -#endif - -#endif diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 3ba8acc5e0..751aede394 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -674,7 +674,6 @@ static void usage(char *pname) /* If we are using the malloc debug code we can't use SIGUSR1 and SIGUSR2 to do debug level changes. */ -#ifndef MEM_MAN #if defined(SIGUSR1) CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); #endif /* SIGUSR1 */ @@ -682,7 +681,6 @@ static void usage(char *pname) #if defined(SIGUSR2) CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); #endif /* SIGUSR2 */ -#endif /* MEM_MAN */ while( EOF != (opt = getopt( argc, argv, "Vaos:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:" )) ) diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 0750d8dbb8..2931356334 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -148,14 +148,6 @@ do a (presumably graceful) quit... static void cmd_quit(struct client_info *info) { rpcclient_stop(); -#ifdef MEM_MAN - { - extern FILE* dbf; - smb_mem_write_status(dbf); - smb_mem_write_errors(dbf); - smb_mem_write_verbose(dbf); - } -#endif exit(0); } diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 1c6d6536ad..0d45f11693 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -693,7 +693,6 @@ static void usage(char *pname) /* If we are using the malloc debug code we can't use SIGUSR1 and SIGUSR2 to do debug level changes. */ -#ifndef MEM_MAN #if defined(SIGUSR1) CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); #endif /* SIGUSR1 */ @@ -701,7 +700,6 @@ static void usage(char *pname) #if defined(SIGUSR2) CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); #endif /* SIGUSR2 */ -#endif /* MEM_MAN */ DEBUG(3,( "loaded services\n")); -- cgit