]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/abandon.c
ITS#8262 add ldap_build_*_req functions
[openldap] / libraries / libldap / abandon.c
index b28811fa2228bb8512766567b8e297a836be3c0f..c45d544a4dd1add0c14518f9dd63ad176b73a074 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2014 The OpenLDAP Foundation.
+ * Copyright 1998-2015 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -278,23 +278,29 @@ start_again:;
        }
 
        if ( lr != NULL ) {
+               LDAPConn *lc;
+               int freeconn = 0;
                if ( sendabandon || lr->lr_status == LDAP_REQST_WRITING ) {
+                       freeconn = 1;
+                       lc = lr->lr_conn;
+               }
+               if ( origid == msgid ) {
+                       ldap_free_request( ld, lr );
+
+               } else {
+                       lr->lr_abandoned = 1;
+               }
+
+               if ( freeconn ) {
                        /* release ld_req_mutex while grabbing ld_conn_mutex to
                         * prevent deadlock.
                         */
                        LDAP_MUTEX_UNLOCK( &ld->ld_req_mutex );
                        LDAP_MUTEX_LOCK( &ld->ld_conn_mutex );
-                       ldap_free_connection( ld, lr->lr_conn, 0, 1 );
+                       ldap_free_connection( ld, lc, 0, 1 );
                        LDAP_MUTEX_UNLOCK( &ld->ld_conn_mutex );
                        LDAP_MUTEX_LOCK( &ld->ld_req_mutex );
                }
-
-               if ( origid == msgid ) {
-                       ldap_free_request( ld, lr );
-
-               } else {
-                       lr->lr_abandoned = 1;
-               }
        }
 
        LDAP_MUTEX_LOCK( &ld->ld_abandon_mutex );