]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/unbind.c
fix memory leak (ITS#3862)
[openldap] / servers / slapd / back-meta / unbind.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2005 The OpenLDAP Foundation.
5  * Portions Copyright 2001-2003 Pierangelo Masarati.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in the file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by the Howard Chu for inclusion
19  * in OpenLDAP Software and subsequently enhanced by Pierangelo
20  * Masarati.
21  */
22
23 #include "portable.h"
24
25 #include <stdio.h>
26
27 #include <ac/socket.h>
28 #include <ac/string.h>
29
30 #include "slap.h"
31 #include "../back-ldap/back-ldap.h"
32 #include "back-meta.h"
33
34 int
35 meta_back_conn_destroy(
36                 Backend         *be,
37                 Connection      *conn
38 )
39 {
40         struct metainfo *li = ( struct metainfo * )be->be_private;
41         struct metaconn *lc, lc_curr;
42         int             i;
43                 
44
45 #ifdef NEW_LOGGING
46         LDAP_LOG( BACK_META, ENTRY,
47                 "meta_back_conn_destroy: fetching conn %ld\n", conn->c_connid, 0, 0 );
48 #else /* !NEW_LOGGING */
49         Debug( LDAP_DEBUG_TRACE,
50                 "=>meta_back_conn_destroy: fetching conn %ld\n%s%s",
51                 conn->c_connid, "", "" );
52 #endif /* !NEW_LOGGING */
53         
54         lc_curr.conn = conn;
55         
56         ldap_pvt_thread_mutex_lock( &li->conn_mutex );
57         lc = avl_delete( &li->conntree, ( caddr_t )&lc_curr,
58                         meta_back_conn_cmp );
59         ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
60
61         /*
62          * Cleanup rewrite session
63          */
64         for ( i = 0; i < li->ntargets; ++i ) {
65                 rewrite_session_delete( li->targets[ i ]->rwmap.rwm_rw, conn );
66         }
67
68         if ( lc ) {
69 #ifdef NEW_LOGGING
70                 LDAP_LOG( BACK_META, INFO,
71                         "meta_back_conn_destroy: destroying conn %ld\n",
72                         lc->conn->c_connid, 0, 0 );
73 #else /* !NEW_LOGGING */
74                 Debug( LDAP_DEBUG_TRACE,
75                         "=>meta_back_conn_destroy: destroying conn %ld\n%s%s",
76                         lc->conn->c_connid, "", "" );
77 #endif /* !NEW_LOGGING */
78                 
79                 /*
80                  * Cleanup rewrite session
81                  */
82                 for ( i = 0; i < li->ntargets; ++i ) {
83                         if ( lc->conns[ i ].ld == NULL ) {
84                                 continue;
85                         }
86
87                         meta_clear_one_candidate( &lc->conns[ i ], 1 );
88                 }
89
90                 free( lc->conns );
91                 free( lc );
92         }
93
94         /* no response to unbind */
95
96         return 0;
97 }
98