From f4e74d51f5cb02769c02230d1d78692c859c5fb0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Kuzn=C3=ADk?= <ondra@mistotebe.net>
Date: Wed, 19 Jan 2022 10:26:45 +0000
Subject: [PATCH] ITS#9781 Relax refcount assertion for referrals

---
 libraries/libldap/request.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c
index b72b875b4..95e402a70 100644
--- a/libraries/libldap/request.c
+++ b/libraries/libldap/request.c
@@ -1667,9 +1667,9 @@ ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid )
 
 	lr = ldap_tavl_find( ld->ld_requests, &needle, ldap_req_cmp );
 	if ( lr != NULL && lr->lr_status != LDAP_REQST_COMPLETED ) {
-		/* try_read1msg is the only user at the moment and we would free it
-		 * multiple times if retrieving the request again */
-		assert( lr->lr_refcnt == 0 );
+		/* lr_refcnt is only negative when we removed it from ld_requests
+		 * already, it is positive if we have sub-requests (referrals) */
+		assert( lr->lr_refcnt >= 0 );
 		lr->lr_refcnt++;
 		Debug3( LDAP_DEBUG_TRACE, "ldap_find_request_by_msgid: "
 				"msgid %d, lr %p lr->lr_refcnt = %d\n",
-- 
2.33.0

