mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-21 03:10:25 +08:00
don't leak callbacks if stuff cannot be registered; provide a means to dispose of private stuff if required
This commit is contained in:
parent
c3960b98d3
commit
6193ee4003
@ -152,6 +152,7 @@ bdb_monitor_update(
|
||||
return SLAP_CB_CONTINUE;
|
||||
}
|
||||
|
||||
#if 0 /* uncomment if required */
|
||||
static int
|
||||
bdb_monitor_modify(
|
||||
Operation *op,
|
||||
@ -161,11 +162,12 @@ bdb_monitor_modify(
|
||||
{
|
||||
return SLAP_CB_CONTINUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
bdb_monitor_free(
|
||||
Entry *e,
|
||||
void *priv )
|
||||
void **priv )
|
||||
{
|
||||
struct berval values[ 2 ];
|
||||
Modification mod = { 0 };
|
||||
@ -176,6 +178,7 @@ bdb_monitor_free(
|
||||
int i, rc;
|
||||
|
||||
/* NOTE: if slap_shutdown != 0, priv might have already been freed */
|
||||
*priv = NULL;
|
||||
|
||||
/* Remove objectClass */
|
||||
mod.sm_op = LDAP_MOD_DELETE;
|
||||
|
@ -265,9 +265,11 @@ done:;
|
||||
static int
|
||||
ldap_back_monitor_free(
|
||||
Entry *e,
|
||||
void *priv )
|
||||
void **priv )
|
||||
{
|
||||
ldapinfo_t *li = (ldapinfo_t *)priv;
|
||||
ldapinfo_t *li = (ldapinfo_t *)(*priv);
|
||||
|
||||
*priv = NULL;
|
||||
|
||||
if ( !slapd_shutdown && !BER_BVISNULL( &li->li_monitor_info.lmi_rdn ) ) {
|
||||
ldap_back_monitor_info_destroy( li );
|
||||
@ -306,7 +308,6 @@ static int
|
||||
ldap_back_monitor_initialize( void )
|
||||
{
|
||||
int i, code;
|
||||
const char *err;
|
||||
ConfigArgs c;
|
||||
char *argv[ 3 ];
|
||||
|
||||
|
@ -39,9 +39,13 @@ typedef struct monitor_callback_t {
|
||||
int (*mc_modify)( Operation *op, SlapReply *rs, Entry *e, void *priv );
|
||||
/* modify callback
|
||||
for user-defined entries */
|
||||
int (*mc_free)( Entry *e, void *priv );
|
||||
int (*mc_free)( Entry *e, void **priv );
|
||||
/* delete callback
|
||||
for user-defined entries */
|
||||
void (*mc_dispose)( void **priv );
|
||||
/* dispose callback
|
||||
to dispose of the callback
|
||||
private data itself */
|
||||
void *mc_private; /* opaque pointer to
|
||||
private data */
|
||||
struct monitor_callback_t *mc_next;
|
||||
|
@ -405,7 +405,7 @@ monitor_entry_destroy( void *v_mc )
|
||||
monitor_callback_t *next = cb->mc_next;
|
||||
|
||||
if ( cb->mc_free ) {
|
||||
cb->mc_free( mc->mc_e, cb->mc_private );
|
||||
(void)cb->mc_free( mc->mc_e, &cb->mc_private );
|
||||
}
|
||||
ch_free( mp->mp_cb );
|
||||
|
||||
|
@ -992,7 +992,6 @@ done:;
|
||||
return -1;
|
||||
}
|
||||
|
||||
done_limbo:;
|
||||
if ( *elpp != NULL ) {
|
||||
el.el_next = NULL;
|
||||
**elpp = el;
|
||||
@ -1080,7 +1079,7 @@ monitor_back_unregister_entry(
|
||||
monitor_callback_t *next = cb->mc_next;
|
||||
|
||||
if ( cb->mc_free ) {
|
||||
(void)cb->mc_free( e, cb->mc_private );
|
||||
(void)cb->mc_free( e, &cb->mc_private );
|
||||
}
|
||||
ch_free( cb );
|
||||
|
||||
@ -1208,7 +1207,7 @@ monitor_back_unregister_entry_parent(
|
||||
for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
|
||||
if ( *cbp == target_cb ) {
|
||||
if ( (*cbp)->mc_free ) {
|
||||
(void)(*cbp)->mc_free( e, (*cbp)->mc_private );
|
||||
(void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
|
||||
}
|
||||
*cbp = (*cbp)->mc_next;
|
||||
ch_free( target_cb );
|
||||
@ -1370,7 +1369,7 @@ monitor_back_unregister_entry_attrs(
|
||||
for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
|
||||
if ( *cbp == target_cb ) {
|
||||
if ( (*cbp)->mc_free ) {
|
||||
(void)(*cbp)->mc_free( e, (*cbp)->mc_private );
|
||||
(void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
|
||||
}
|
||||
*cbp = (*cbp)->mc_next;
|
||||
ch_free( target_cb );
|
||||
@ -1837,7 +1836,6 @@ monitor_back_initialize(
|
||||
};
|
||||
|
||||
int i, rc;
|
||||
const char *text;
|
||||
monitor_info_t *mi = &monitor_info;
|
||||
ConfigArgs c;
|
||||
char *argv[ 3 ];
|
||||
@ -2231,10 +2229,11 @@ monitor_back_db_open(
|
||||
|
||||
for ( ; el; ) {
|
||||
entry_limbo_t *tmp;
|
||||
int rc;
|
||||
|
||||
switch ( el->el_type ) {
|
||||
case LIMBO_ENTRY:
|
||||
monitor_back_register_entry(
|
||||
rc = monitor_back_register_entry(
|
||||
el->el_e,
|
||||
el->el_cb,
|
||||
el->el_mss,
|
||||
@ -2242,7 +2241,7 @@ monitor_back_db_open(
|
||||
break;
|
||||
|
||||
case LIMBO_ENTRY_PARENT:
|
||||
monitor_back_register_entry_parent(
|
||||
rc = monitor_back_register_entry_parent(
|
||||
el->el_e,
|
||||
el->el_cb,
|
||||
el->el_mss,
|
||||
@ -2254,7 +2253,7 @@ monitor_back_db_open(
|
||||
|
||||
|
||||
case LIMBO_ATTRS:
|
||||
monitor_back_register_entry_attrs(
|
||||
rc = monitor_back_register_entry_attrs(
|
||||
&el->el_ndn,
|
||||
el->el_a,
|
||||
el->el_cb,
|
||||
@ -2264,7 +2263,7 @@ monitor_back_db_open(
|
||||
break;
|
||||
|
||||
case LIMBO_CB:
|
||||
monitor_back_register_entry_callback(
|
||||
rc = monitor_back_register_entry_callback(
|
||||
&el->el_ndn,
|
||||
el->el_cb,
|
||||
&el->el_nbase,
|
||||
@ -2291,6 +2290,12 @@ monitor_back_db_open(
|
||||
if ( !BER_BVISNULL( &el->el_filter ) ) {
|
||||
ber_memfree( el->el_filter.bv_val );
|
||||
}
|
||||
if ( el->el_cb && rc != 0 ) {
|
||||
if ( el->el_cb->mc_dispose ) {
|
||||
el->el_cb->mc_dispose( &el->el_cb->mc_private );
|
||||
}
|
||||
ch_free( el->el_cb );
|
||||
}
|
||||
|
||||
tmp = el;
|
||||
el = el->el_next;
|
||||
|
Loading…
Reference in New Issue
Block a user