From da0a060e4d2e41e02118622ab5039b119a01d0af Mon Sep 17 00:00:00 2001
From: HAMANO Tsukasa <hamano@osstech.co.jp>
Date: Thu, 2 Sep 2021 14:00:36 +0900
Subject: [PATCH] ITS#9631 back-wt: closing cache db politely

---
 servers/slapd/back-wt/init.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/servers/slapd/back-wt/init.c b/servers/slapd/back-wt/init.c
index ba828bf109..730ccd261f 100644
--- a/servers/slapd/back-wt/init.c
+++ b/servers/slapd/back-wt/init.c
@@ -232,20 +232,25 @@ wt_db_close( BackendDB *be, ConfigReply *cr )
 	struct wt_info *wi = (struct wt_info *) be->be_private;
 	int rc;
 
-	if ( !wi->wi_conn ) {
-		return -1;
+	if ( wi->wi_cache ) {
+		rc = wi->wi_cache->close(wi->wi_cache, NULL);
+		if( rc ) {
+			Debug( LDAP_DEBUG_ANY,
+				   "wt_db_close: cannot close cache database (%d).\n", rc );
+			return -1;
+		}
 	}
 
-	rc = wi->wi_conn->close(wi->wi_conn, NULL);
-	if( rc ) {
-		int saved_errno = errno;
-		Debug( LDAP_DEBUG_ANY,
-			   "wt_db_close: cannot close database (%d).\n", saved_errno );
-		return -1;
+	if ( wi->wi_conn ) {
+		rc = wi->wi_conn->close(wi->wi_conn, NULL);
+		if( rc ) {
+			Debug( LDAP_DEBUG_ANY,
+				   "wt_db_close: cannot close database (%d).\n", rc );
+			return -1;
+		}
+		wi->wi_flags &= ~WT_IS_OPEN;
 	}
 
-	wi->wi_flags &= ~WT_IS_OPEN;
-
     return LDAP_SUCCESS;
 }
 
-- 
GitLab