[Date Prev][Date Next] [Chronological] [Thread] [Top]

(ITS#5607) Double close problem for SQL handles in back-sql

Full_Name: Ben Schmidt
Version: 2.4.10
OS: MinGW32, Mac OS X
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (

I have recently cross-compiled OpenLDAP for MinGW32 on Mac OS X. I found two
bugs in the source code relating to shutdown/freeing structures.

This is the second. It relates to back-sql, which I realise is unsupported on
this platform, but seems to work very nicely once this and another bugfix or two
(my other posts) are made. Mind you, I have only done a small amount of testing,
and don't really understand what I am doing, as I am a complete newbie to LDAP.
After sending these patches I intend to embark on a reading of your
Administrator's Guide to learn.

>From the source code, though, I don't see why the problem would only apply to
this platform anyway. It is this:

When an SQL handle is opened, it is registered to be freed. When it is freed,
however, it is not deregistered, so can easily be freed twice, particularly as
to load the schemas the database connection is opened and closed. I suggest this
patch to fix it (the patch looks larger than it really is as some code needed to
be moved to ensure correct definition order):

diff -ru --exclude=Makefile openldap-2.4.10/servers/slapd/back-sql/sql-wrap.c
--- openldap-2.4.10/servers/slapd/back-sql/sql-wrap.c	2008-02-12
10:26:48.000000000 +1100
+++ openldap/servers/slapd/back-sql/sql-wrap.c	2008-06-28 22:29:25.000000000
@@ -462,28 +462,31 @@
 	return LDAP_SUCCESS;
+static void	*backsql_db_conn_dummy;
+static void
+	void		*key,
+	void		*data )
+	backsql_close_db_handle( (SQLHDBC)data );
 backsql_free_db_conn( Operation *op, SQLHDBC dbh )
 	Debug( LDAP_DEBUG_TRACE, "==>backsql_free_db_conn()\n", 0, 0, 0 );
 	(void)backsql_close_db_handle( dbh );
+	ldap_pvt_thread_pool_setkey( op->o_threadctx,
+			&backsql_db_conn_dummy, (void *)SQL_NULL_HDBC,
+			backsql_db_conn_keyfree, NULL, NULL );
 	Debug( LDAP_DEBUG_TRACE, "<==backsql_free_db_conn()\n", 0, 0, 0 );
 	return LDAP_SUCCESS;
-static void	*backsql_db_conn_dummy;
-static void
-	void		*key,
-	void		*data )
-	backsql_close_db_handle( (SQLHDBC)data );
 backsql_get_db_conn( Operation *op, SQLHDBC *dbhp )

I could not find this issue already in your tracker.