From: Kurt Zeilenga Date: Thu, 19 Aug 1999 17:06:28 +0000 (+0000) Subject: Add hacks to allow debugging with CSRI malloc. X-Git-Tag: TWEB_OL_BASE~159 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c51f35fe0f505c608a2ba2fdd4b65b9465014b3d;p=openldap Add hacks to allow debugging with CSRI malloc. (test001-populate runs without leak) Free global entry string buffer on shutdown. --- diff --git a/include/ac/stdlib.h b/include/ac/stdlib.h index d642b45910..6fc2f6a4d0 100644 --- a/include/ac/stdlib.h +++ b/include/ac/stdlib.h @@ -12,6 +12,12 @@ #ifndef _AC_STDLIB_H #define _AC_STDLIB_H +#if defined( HAVE_CSRIMALLOC ) +#include +#define MALLOC_TRACE +#include +#endif + #include /* Ignore malloc.h if we have STDC_HEADERS */ diff --git a/servers/slapd/add.c b/servers/slapd/add.c index 441ac20684..1d37dad4e3 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -83,8 +83,6 @@ do_add( Connection *conn, Operation *op ) e->e_ndn = ndn; e->e_private = NULL; - dn = NULL; - Debug( LDAP_DEBUG_ARGS, " do_add: ndn (%s)\n", e->e_ndn, 0, 0 ); /* get the attrs */ diff --git a/servers/slapd/ch_malloc.c b/servers/slapd/ch_malloc.c index 61bf6d4ee1..5c57c7c021 100644 --- a/servers/slapd/ch_malloc.c +++ b/servers/slapd/ch_malloc.c @@ -4,6 +4,8 @@ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ +#define CH_FREE 1 + #include "portable.h" #include @@ -15,6 +17,8 @@ #include "slap.h" +#ifndef CSRIMALLOC + void * ch_malloc( ber_len_t size @@ -97,3 +101,5 @@ ch_free( void *ptr ) { ber_memfree( ptr ); } + +#endif diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index 370864ba77..fd6fd49a5f 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -19,6 +19,15 @@ static unsigned char *ebuf; /* buf returned by entry2str */ static unsigned char *ecur; /* pointer to end of currently used ebuf */ static int emaxsize;/* max size of ebuf */ +int entry_destroy(void) +{ + free( *ebuf ); + ebuf = NULL; + ecur = NULL; + emaxsize = 0; + return 0; +} + Entry * str2entry( char *s ) { diff --git a/servers/slapd/init.c b/servers/slapd/init.c index 5e0fcb3e38..d46b90d3c7 100644 --- a/servers/slapd/init.c +++ b/servers/slapd/init.c @@ -162,6 +162,8 @@ int slap_destroy(void) rc = backend_destroy(); + entry_destroy(); + ldap_pvt_thread_destroy(); /* should destory the above mutex */ diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 9d0544573b..53398e9993 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -159,6 +159,13 @@ int main( int argc, char **argv ) int tls_port = 0; #endif +#ifdef CSRIMALLOC + FILE *leakfile; + if( ( leakfile = fopen( "slapd.leak", "w" )) == NULL ) { + leakfile = stderr; + } +#endif + g_argc = argc; g_argv = argv; @@ -384,6 +391,10 @@ int main( int argc, char **argv ) #endif #endif /* HAVE_WINSOCK */ +#ifdef CSRIMALLOC + mal_leaktrace(1); +#endif + if ( slap_startup( NULL ) != 0 ) { rc = 1; SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 ); @@ -428,6 +439,7 @@ int main( int argc, char **argv ) shutdown: /* remember an error during shutdown */ rc |= slap_shutdown( NULL ); + destroy: /* remember an error during destroy */ rc |= slap_destroy(); @@ -446,6 +458,10 @@ stop: closelog(); slapd_daemon_destroy(); +#ifdef CSRIMALLOC + mal_dumpleaktrace( leakfile ); +#endif + MAIN_RETURN(rc); } diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 5c29a9cf75..59ee788ff7 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -118,12 +118,25 @@ extern Attribute *backend_subschemasubentry( Backend * ); * ch_malloc.c */ +#ifdef CSRIMALLOC +#define ch_malloc malloc +#define ch_realloc realloc +#define ch_calloc calloc +#define ch_strdup strdup +#define ch_free free + +#else void * ch_malloc LDAP_P(( ber_len_t size )); void * ch_realloc LDAP_P(( void *block, ber_len_t size )); void * ch_calloc LDAP_P(( ber_len_t nelem, ber_len_t size )); char * ch_strdup LDAP_P(( const char *string )); void ch_free LDAP_P(( void * )); + +#ifndef CH_FREE +#undef free #define free ch_free +#endif +#endif /* * charray.c @@ -206,6 +219,8 @@ void build_new_dn LDAP_P(( char ** new_dn, char *e_dn, char * p_dn, * entry.c */ +int entry_destroy LDAP_P((void)); + Entry * str2entry LDAP_P(( char *s )); char * entry2str LDAP_P(( Entry *e, int *len )); void entry_free LDAP_P(( Entry *e ));