]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/result.c
ITS#6689
[openldap] / libraries / libldap / result.c
index ad62a02d30749e00d16a9dcd38f86825ad630ca3..05580b793cfa8215566cb412215f35021927bf8b 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2009 The OpenLDAP Foundation.
+ * Copyright 1998-2010 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -276,7 +276,7 @@ wait4msg(
        }
 #endif /* LDAP_DEBUG */
 
-       if ( timeout != NULL ) {
+       if ( timeout != NULL && timeout->tv_sec != -1 ) {
                tv0 = *timeout;
                tv = *timeout;
                tvp = &tv;
@@ -747,8 +747,9 @@ nextresp2:
                        }
 
                        /* Do we need to check for referrals? */
-                       if ( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ||
-                                       lr->lr_parent != NULL )
+                       if ( tag != LDAP_RES_BIND &&
+                               ( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ||
+                                       lr->lr_parent != NULL ))
                        {
                                char            **refs = NULL;
                                ber_len_t       len;
@@ -845,6 +846,10 @@ nextresp2:
                                return( -1 );   /* fatal error */
                        }
                        lr->lr_res_errno = LDAP_SUCCESS; /* sucessfully chased referral */
+                       if ( lr->lr_res_matched ) {
+                               LDAP_FREE( lr->lr_res_matched );
+                               lr->lr_res_matched = NULL;
+                       }
 
                } else {
                        if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL ) {
@@ -989,6 +994,7 @@ nextresp2:
 
                        /* need to return -1, because otherwise
                         * a valid result is expected */
+                       ld->ld_errno = lderr;
                        return -1;
                }
        }