]> git.sur5r.net Git - openldap/commitdiff
plug leaks; fix map initialization
authorPierangelo Masarati <ando@openldap.org>
Mon, 1 Aug 2005 22:40:18 +0000 (22:40 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 1 Aug 2005 22:40:18 +0000 (22:40 +0000)
servers/slapd/overlays/rwm.c
servers/slapd/overlays/rwmmap.c

index 9369a1ade3a3a362c5cde07a659f6a383b77ffd0..20a754fa7c5875ede0d2fe6649c0cdc9772b3326 100644 (file)
@@ -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, "<suffix massage>", 1, 2, rargv );
-
-               rargv[ 0 ] = "rewriteContext";
-               rargv[ 1 ] = "default";
-               rargv[ 2 ] = NULL;
-               rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 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, "<suffix massage>", 1, 2, rargv );
+
+       rargv[ 0 ] = "rewriteContext";
+       rargv[ 1 ] = "default";
+       rargv[ 2 ] = NULL;
+       rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 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;
index 475418e895b0e746e4dd75ee5a8ef38904a99f75..4c573f3b423388f0ca1a2cc0d40149f2e496430b 100644 (file)
@@ -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 );