From c984c229d682168bcb8caaa8e18dfd6833c1da5b Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 8 Aug 2005 20:45:10 +0000 Subject: [PATCH] plug more one-time leaks; rearrange subsystems setup --- servers/slapd/back-monitor/back-monitor.h | 2 + servers/slapd/back-monitor/conn.c | 21 ++++++++- servers/slapd/back-monitor/database.c | 13 +++-- servers/slapd/back-monitor/init.c | 35 ++++++++++---- servers/slapd/back-monitor/log.c | 32 ++++++++++++- servers/slapd/back-monitor/operation.c | 38 +++++++++++++-- .../slapd/back-monitor/proto-back-monitor.h | 47 ------------------- servers/slapd/back-monitor/rww.c | 13 +++-- servers/slapd/back-monitor/sent.c | 35 ++++++++++++-- servers/slapd/back-monitor/thread.c | 17 +++++-- servers/slapd/back-monitor/time.c | 13 +++-- 11 files changed, 185 insertions(+), 81 deletions(-) diff --git a/servers/slapd/back-monitor/back-monitor.h b/servers/slapd/back-monitor/back-monitor.h index 15c853c86b..e688f943c3 100644 --- a/servers/slapd/back-monitor/back-monitor.h +++ b/servers/slapd/back-monitor/back-monitor.h @@ -251,6 +251,8 @@ typedef struct monitor_subsys_t { /* initialize entry and subentries */ int ( *mss_open )( BackendDB *, struct monitor_subsys_t *ms ); + /* destroy structure */ + int ( *mss_destroy )( BackendDB *, struct monitor_subsys_t *ms ); /* update existing dynamic entry and subentries */ int ( *mss_update )( Operation *, SlapReply *, Entry * ); /* create new dynamic subentries */ diff --git a/servers/slapd/back-monitor/conn.c b/servers/slapd/back-monitor/conn.c index 6f5a187e71..b5fcab790a 100644 --- a/servers/slapd/back-monitor/conn.c +++ b/servers/slapd/back-monitor/conn.c @@ -32,6 +32,20 @@ #define MONITOR_LEGACY_CONN #endif +static int +monitor_subsys_conn_update( + Operation *op, + SlapReply *rs, + Entry *e ); + +static int +monitor_subsys_conn_create( + Operation *op, + SlapReply *rs, + struct berval *ndn, + Entry *e_parent, + Entry **ep ); + int monitor_subsys_conn_init( BackendDB *be, @@ -45,6 +59,9 @@ monitor_subsys_conn_init( assert( be != NULL ); + ms->mss_update = monitor_subsys_conn_update; + ms->mss_create = monitor_subsys_conn_create; + mi = ( monitor_info_t * )be->be_private; if ( monitor_cache_get( mi, &ms->mss_ndn, &e_conn ) ) { @@ -170,7 +187,7 @@ monitor_subsys_conn_init( return( 0 ); } -int +static int monitor_subsys_conn_update( Operation *op, SlapReply *rs, @@ -469,7 +486,7 @@ conn_create( return SLAP_CB_CONTINUE; } -int +static int monitor_subsys_conn_create( Operation *op, SlapReply *rs, diff --git a/servers/slapd/back-monitor/database.c b/servers/slapd/back-monitor/database.c index 69df414617..ae234a143b 100644 --- a/servers/slapd/back-monitor/database.c +++ b/servers/slapd/back-monitor/database.c @@ -54,6 +54,12 @@ static int monitor_back_add_plugin( monitor_info_t *mi, Backend *be, Entry *e ); #define PATH_MAX 4095 #endif /* ! PATH_MAX */ +static int +monitor_subsys_database_modify( + Operation *op, + SlapReply *rs, + Entry *e ); + static struct restricted_ops_t { struct berval op; unsigned int tag; @@ -129,6 +135,8 @@ monitor_subsys_database_init( assert( be != NULL ); + ms->mss_modify = monitor_subsys_database_modify; + mi = ( monitor_info_t * )be->be_private; ms_backend = monitor_back_get_subsys( SLAPD_MONITOR_BACKEND_NAME ); @@ -545,12 +553,11 @@ value_mask( BerVarray v, slap_mask_t cur, slap_mask_t *delta ) return LDAP_SUCCESS; } -int +static int monitor_subsys_database_modify( Operation *op, SlapReply *rs, - Entry *e -) + Entry *e ) { monitor_info_t *mi = (monitor_info_t *)op->o_bd->be_private; int rc = LDAP_OTHER; diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index 4107471099..b665f9825b 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -62,6 +62,7 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_backend_init, + NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL /* modify */ @@ -72,8 +73,9 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_VOLATILE_CH, monitor_subsys_conn_init, - monitor_subsys_conn_update, - monitor_subsys_conn_create, + NULL, /* destroy */ + NULL, /* update */ + NULL, /* create */ NULL /* modify */ }, { SLAPD_MONITOR_DATABASE_NAME, @@ -82,9 +84,10 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_database_init, + NULL, /* destroy */ NULL, /* update */ NULL, /* create */ - monitor_subsys_database_modify + NULL /* modify */ }, { SLAPD_MONITOR_LISTENER_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, @@ -92,6 +95,7 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_listener_init, + NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL /* modify */ @@ -103,9 +107,10 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_NONE, monitor_subsys_log_init, + NULL, /* destroy */ NULL, /* update */ NULL, /* create */ - monitor_subsys_log_modify + NULL, /* modify */ }, { SLAPD_MONITOR_OPS_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, @@ -113,7 +118,8 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_ops_init, - monitor_subsys_ops_update, + NULL, /* destroy */ + NULL, /* update */ NULL, /* create */ NULL, /* modify */ }, { @@ -123,6 +129,7 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_overlay_init, + NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL, /* modify */ @@ -133,6 +140,7 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_NONE, NULL, /* init */ + NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL /* modify */ @@ -143,7 +151,8 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_sent_init, - monitor_subsys_sent_update, + NULL, /* destroy */ + NULL, /* update */ NULL, /* create */ NULL, /* modify */ }, { @@ -153,7 +162,8 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_thread_init, - monitor_subsys_thread_update, + NULL, /* destroy */ + NULL, /* update */ NULL, /* create */ NULL /* modify */ }, { @@ -163,7 +173,8 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_time_init, - monitor_subsys_time_update, + NULL, /* destroy */ + NULL, /* update */ NULL, /* create */ NULL, /* modify */ }, { @@ -173,6 +184,7 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_NONE, NULL, /* init */ + NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL /* modify */ @@ -183,7 +195,8 @@ static struct monitor_subsys_t known_monitor_subsys[] = { BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_rww_init, - monitor_subsys_rww_update, + NULL, /* destroy */ + NULL, /* update */ NULL, /* create */ NULL /* modify */ }, { NULL } @@ -1766,6 +1779,10 @@ monitor_back_db_destroy( int i; for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) { + if ( monitor_subsys[ i ]->mss_destroy ) { + monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] ); + } + if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) { ch_free( monitor_subsys[ i ]->mss_rdn.bv_val ); } diff --git a/servers/slapd/back-monitor/log.c b/servers/slapd/back-monitor/log.c index 5be1d20741..6a390891d4 100644 --- a/servers/slapd/back-monitor/log.c +++ b/servers/slapd/back-monitor/log.c @@ -31,6 +31,17 @@ #include "ldif.h" #include "back-monitor.h" +static int +monitor_subsys_log_destroy( + BackendDB *be, + monitor_subsys_t *ms ); + +static int +monitor_subsys_log_modify( + Operation *op, + SlapReply *rs, + Entry *e ); + /* * log mutex */ @@ -77,6 +88,9 @@ monitor_subsys_log_init( Entry *e; int i; + ms->mss_destroy = monitor_subsys_log_destroy; + ms->mss_modify = monitor_subsys_log_modify; + ldap_pvt_thread_mutex_init( &monitor_log_mutex ); mi = ( monitor_info_t * )be->be_private; @@ -118,7 +132,23 @@ monitor_subsys_log_init( return( 0 ); } -int +static int +monitor_subsys_log_destroy( + BackendDB *be, + monitor_subsys_t *ms ) +{ + int i; + + for ( i = 0; int_2_level[ i ].i != 0; i++ ) { + if ( !BER_BVISNULL( &int_2_level[ i ].n ) ) { + ch_free( int_2_level[ i ].n.bv_val ); + } + } + + return 0; +} + +static int monitor_subsys_log_modify( Operation *op, SlapReply *rs, diff --git a/servers/slapd/back-monitor/operation.c b/servers/slapd/back-monitor/operation.c index 8b8cac4530..f7aa7c6483 100644 --- a/servers/slapd/back-monitor/operation.c +++ b/servers/slapd/back-monitor/operation.c @@ -45,11 +45,21 @@ struct monitor_ops_t { { BER_BVNULL, BER_BVNULL } }; +static int +monitor_subsys_ops_destroy( + BackendDB *be, + monitor_subsys_t *ms ); + +static int +monitor_subsys_ops_update( + Operation *op, + SlapReply *rs, + Entry *e ); + int monitor_subsys_ops_init( BackendDB *be, - monitor_subsys_t *ms -) + monitor_subsys_t *ms ) { monitor_info_t *mi; @@ -61,6 +71,9 @@ monitor_subsys_ops_init( assert( be != NULL ); + ms->mss_destroy = monitor_subsys_ops_destroy; + ms->mss_update = monitor_subsys_ops_update; + mi = ( monitor_info_t * )be->be_private; if ( monitor_cache_get( mi, @@ -152,12 +165,27 @@ monitor_subsys_ops_init( return( 0 ); } -int +static int +monitor_subsys_ops_destroy( + BackendDB *be, + monitor_subsys_t *ms ) +{ + int i; + + for ( i = 0; i < SLAP_OP_LAST; i++ ) { + if ( !BER_BVISNULL( &monitor_op[ i ].nrdn ) ) { + ch_free( monitor_op[ i ].nrdn.bv_val ); + } + } + + return 0; +} + +static int monitor_subsys_ops_update( Operation *op, SlapReply *rs, - Entry *e -) + Entry *e ) { monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private; diff --git a/servers/slapd/back-monitor/proto-back-monitor.h b/servers/slapd/back-monitor/proto-back-monitor.h index 6de478a1cc..70007135bd 100644 --- a/servers/slapd/back-monitor/proto-back-monitor.h +++ b/servers/slapd/back-monitor/proto-back-monitor.h @@ -79,18 +79,6 @@ extern int monitor_subsys_conn_init LDAP_P(( BackendDB *be, monitor_subsys_t *ms )); -extern int -monitor_subsys_conn_update LDAP_P(( - Operation *op, - SlapReply *rs, - Entry *e )); -extern int -monitor_subsys_conn_create LDAP_P(( - Operation *op, - SlapReply *rs, - struct berval *ndn, - Entry *e_parent, - Entry **ep )); /* * databases @@ -99,11 +87,6 @@ extern int monitor_subsys_database_init LDAP_P(( BackendDB *be, monitor_subsys_t *ms )); -extern int -monitor_subsys_database_modify LDAP_P(( - Operation *op, - SlapReply *rs, - Entry *e )); /* * entry @@ -194,11 +177,6 @@ extern int monitor_subsys_log_init LDAP_P(( BackendDB *be, monitor_subsys_t *ms )); -extern int -monitor_subsys_log_modify LDAP_P(( - Operation *op, - SlapReply *rs, - Entry *e )); /* * operations @@ -207,11 +185,6 @@ extern int monitor_subsys_ops_init LDAP_P(( BackendDB *be, monitor_subsys_t *ms )); -extern int -monitor_subsys_ops_update LDAP_P(( - Operation *op, - SlapReply *rs, - Entry *e )); /* * overlay @@ -228,11 +201,6 @@ extern int monitor_subsys_sent_init LDAP_P(( BackendDB *be, monitor_subsys_t *ms )); -extern int -monitor_subsys_sent_update LDAP_P(( - Operation *op, - SlapReply *rs, - Entry *e )); /* * threads @@ -241,11 +209,6 @@ extern int monitor_subsys_thread_init LDAP_P(( BackendDB *be, monitor_subsys_t *ms )); -extern int -monitor_subsys_thread_update LDAP_P(( - Operation *op, - SlapReply *rs, - Entry *e )); /* * time @@ -253,11 +216,6 @@ monitor_subsys_thread_update LDAP_P(( extern int monitor_subsys_time_init LDAP_P(( BackendDB *be, monitor_subsys_t *ms )); -extern int -monitor_subsys_time_update LDAP_P(( - Operation *op, - SlapReply *rs, - Entry *e )); /* * waiters @@ -266,11 +224,6 @@ extern int monitor_subsys_rww_init LDAP_P(( BackendDB *be, monitor_subsys_t *ms )); -extern int -monitor_subsys_rww_update LDAP_P(( - Operation *op, - SlapReply *rs, - Entry *e )); /* * former external.h diff --git a/servers/slapd/back-monitor/rww.c b/servers/slapd/back-monitor/rww.c index 8f6f50ce40..0edea5d079 100644 --- a/servers/slapd/back-monitor/rww.c +++ b/servers/slapd/back-monitor/rww.c @@ -28,6 +28,12 @@ #include "lutil.h" #include "back-monitor.h" +static int +monitor_subsys_rww_update( + Operation *op, + SlapReply *rs, + Entry *e ); + enum { MONITOR_RWW_READ = 0, MONITOR_RWW_WRITE, @@ -58,6 +64,8 @@ monitor_subsys_rww_init( assert( be != NULL ); + ms->mss_update = monitor_subsys_rww_update; + mi = ( monitor_info_t * )be->be_private; if ( monitor_cache_get( mi, &ms->mss_ndn, &e_conn ) ) { @@ -139,12 +147,11 @@ monitor_subsys_rww_init( return( 0 ); } -int +static int monitor_subsys_rww_update( Operation *op, SlapReply *rs, - Entry *e -) + Entry *e ) { monitor_info_t *mi = (monitor_info_t *)op->o_bd->be_private; Connection *c; diff --git a/servers/slapd/back-monitor/sent.c b/servers/slapd/back-monitor/sent.c index f4909e3b18..f6c0a9f17f 100644 --- a/servers/slapd/back-monitor/sent.c +++ b/servers/slapd/back-monitor/sent.c @@ -27,6 +27,17 @@ #include "slap.h" #include "back-monitor.h" +static int +monitor_subsys_sent_destroy( + BackendDB *be, + monitor_subsys_t *ms ); + +static int +monitor_subsys_sent_update( + Operation *op, + SlapReply *rs, + Entry *e ); + enum { MONITOR_SENT_BYTES = 0, MONITOR_SENT_PDU, @@ -50,8 +61,7 @@ struct monitor_sent_t { int monitor_subsys_sent_init( BackendDB *be, - monitor_subsys_t *ms -) + monitor_subsys_t *ms ) { monitor_info_t *mi; @@ -61,6 +71,9 @@ monitor_subsys_sent_init( assert( be != NULL ); + ms->mss_destroy = monitor_subsys_sent_destroy; + ms->mss_update = monitor_subsys_sent_update; + mi = ( monitor_info_t * )be->be_private; if ( monitor_cache_get( mi, &ms->mss_ndn, &e_sent ) ) { @@ -143,7 +156,23 @@ monitor_subsys_sent_init( return( 0 ); } -int +static int +monitor_subsys_sent_destroy( + BackendDB *be, + monitor_subsys_t *ms ) +{ + int i; + + for ( i = 0; i < MONITOR_SENT_LAST; i++ ) { + if ( !BER_BVISNULL( &monitor_sent[ i ].nrdn ) ) { + ch_free( monitor_sent[ i ].nrdn.bv_val ); + } + } + + return 0; +} + +static int monitor_subsys_sent_update( Operation *op, SlapReply *rs, diff --git a/servers/slapd/back-monitor/thread.c b/servers/slapd/back-monitor/thread.c index 5d393a8e19..c76acaa864 100644 --- a/servers/slapd/back-monitor/thread.c +++ b/servers/slapd/back-monitor/thread.c @@ -29,9 +29,15 @@ #include +static int +monitor_subsys_thread_update( + Operation *op, + SlapReply *rs, + Entry *e ); + /* -* * initializes log subentry -* */ + * initializes log subentry + */ int monitor_subsys_thread_init( BackendDB *be, @@ -43,6 +49,8 @@ monitor_subsys_thread_init( Entry *e, **ep, *e_thread; static char buf[ BACKMONITOR_BUFSIZE ]; + ms->mss_update = monitor_subsys_thread_update; + mi = ( monitor_info_t * )be->be_private; if ( monitor_cache_get( mi, &ms->mss_ndn, &e_thread ) ) { @@ -216,12 +224,11 @@ monitor_subsys_thread_init( return( 0 ); } -int +static int monitor_subsys_thread_update( Operation *op, SlapReply *rs, - Entry *e -) + Entry *e ) { monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private; Attribute *a; diff --git a/servers/slapd/back-monitor/time.c b/servers/slapd/back-monitor/time.c index 02037979b5..61273a6839 100644 --- a/servers/slapd/back-monitor/time.c +++ b/servers/slapd/back-monitor/time.c @@ -31,11 +31,16 @@ #include "proto-slap.h" #include "back-monitor.h" +static int +monitor_subsys_time_update( + Operation *op, + SlapReply *rs, + Entry *e ); + int monitor_subsys_time_init( BackendDB *be, - monitor_subsys_t *ms -) + monitor_subsys_t *ms ) { monitor_info_t *mi; @@ -45,6 +50,8 @@ monitor_subsys_time_init( assert( be != NULL ); + ms->mss_update = monitor_subsys_time_update; + mi = ( monitor_info_t * )be->be_private; if ( monitor_cache_get( mi, @@ -166,7 +173,7 @@ monitor_subsys_time_init( return( 0 ); } -int +static int monitor_subsys_time_update( Operation *op, SlapReply *rs, -- 2.39.5