From 9a64785e4da49db4674aa1a7154ab0a8780fae26 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 1 Aug 2005 22:40:18 +0000 Subject: [PATCH] plug leaks; fix map initialization --- servers/slapd/overlays/rwm.c | 35 ++++++++++++++++----------------- servers/slapd/overlays/rwmmap.c | 16 ++++++++------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/servers/slapd/overlays/rwm.c b/servers/slapd/overlays/rwm.c index 9369a1ade3..20a754fa7c 100644 --- a/servers/slapd/overlays/rwm.c +++ b/servers/slapd/overlays/rwm.c @@ -1419,9 +1419,11 @@ rwm_db_init( slap_overinst *on = (slap_overinst *) be->bd_info; struct ldapmapping *mapping = NULL; struct ldaprwmap *rwmap; +#ifdef ENABLE_REWRITE + char *rargv[ 3 ]; +#endif /* ENABLE_REWRITE */ - rwmap = (struct ldaprwmap *)ch_malloc(sizeof(struct ldaprwmap)); - memset(rwmap, 0, sizeof(struct ldaprwmap)); + rwmap = (struct ldaprwmap *)ch_calloc( 1, sizeof( struct ldaprwmap ) ); #ifdef ENABLE_REWRITE rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT ); @@ -1430,22 +1432,17 @@ rwm_db_init( return -1; } - { - char *rargv[3]; - - /* this rewriteContext by default must be null; - * rules can be added if required */ - rargv[ 0 ] = "rewriteContext"; - rargv[ 1 ] = "searchFilter"; - rargv[ 2 ] = NULL; - rewrite_parse( rwmap->rwm_rw, "", 1, 2, rargv ); - - rargv[ 0 ] = "rewriteContext"; - rargv[ 1 ] = "default"; - rargv[ 2 ] = NULL; - rewrite_parse( rwmap->rwm_rw, "", 2, 2, rargv ); - } - + /* this rewriteContext by default must be null; + * rules can be added if required */ + rargv[ 0 ] = "rewriteContext"; + rargv[ 1 ] = "searchFilter"; + rargv[ 2 ] = NULL; + rewrite_parse( rwmap->rwm_rw, "", 1, 2, rargv ); + + rargv[ 0 ] = "rewriteContext"; + rargv[ 1 ] = "default"; + rargv[ 2 ] = NULL; + rewrite_parse( rwmap->rwm_rw, "", 2, 2, rargv ); #endif /* ENABLE_REWRITE */ if ( rwm_map_init( &rwmap->rwm_oc, &mapping ) != LDAP_SUCCESS || @@ -1485,6 +1482,8 @@ rwm_db_destroy( avl_free( rwmap->rwm_oc.map, rwm_mapping_free ); avl_free( rwmap->rwm_at.remap, NULL ); avl_free( rwmap->rwm_at.map, rwm_mapping_free ); + + ch_free( rwmap ); } return rc; diff --git a/servers/slapd/overlays/rwmmap.c b/servers/slapd/overlays/rwmmap.c index 475418e895..4c573f3b42 100644 --- a/servers/slapd/overlays/rwmmap.c +++ b/servers/slapd/overlays/rwmmap.c @@ -82,19 +82,21 @@ rwm_map_init( struct ldapmap *lm, struct ldapmapping **m ) } /* FIXME: I don't think this is needed any more... */ - rc = slap_str2ad( "objectClass", &mapping->m_src_ad, &text ); + rc = slap_str2ad( "objectClass", &mapping[0].m_src_ad, &text ); if ( rc != LDAP_SUCCESS ) { return rc; } - mapping->m_dst_ad = mapping->m_src_ad; - ber_dupbv( &mapping->m_dst, &mapping->m_src_ad->ad_cname ); - ber_dupbv( &mapping->m_dst, &mapping->m_src ); + mapping[0].m_dst_ad = mapping[0].m_src_ad; + ber_dupbv( &mapping[0].m_src, &mapping[0].m_src_ad->ad_cname ); + ber_dupbv( &mapping[0].m_dst, &mapping[0].m_src ); - mapping[1].m_src = mapping->m_src; - mapping[1].m_dst = mapping->m_dst; + mapping[1].m_src = mapping[0].m_src; + mapping[1].m_dst = mapping[0].m_dst; + mapping[1].m_src_ad = mapping[0].m_src_ad; + mapping[1].m_dst_ad = mapping[1].m_src_ad; - avl_insert( &lm->map, (caddr_t)mapping, + avl_insert( &lm->map, (caddr_t)&mapping[0], rwm_mapping_cmp, rwm_mapping_dup ); avl_insert( &lm->remap, (caddr_t)&mapping[1], rwm_mapping_cmp, rwm_mapping_dup ); -- 2.39.5