From 52c3ee60a1ce0e7e527dc396dd1e1a0e29b7b0ed Mon Sep 17 00:00:00 2001
From: Michael Schroeder <mls@suse.de>
Date: Fri, 10 Jan 2020 15:47:13 +0100
Subject: [PATCH] ndb: only clear the dbenv in the rpmdb if the last reference
 is gone

Otherwise we will segfault if just one index is closed.
---
 lib/backend/ndb/glue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/backend/ndb/glue.c b/lib/backend/ndb/glue.c
index 376e360e3..841c2fe42 100644
--- a/lib/backend/ndb/glue.c
+++ b/lib/backend/ndb/glue.c
@@ -52,8 +52,8 @@ static void closeEnv(rpmdb rdb)
 	if (ndbenv->data)
 	    free(ndbenv->data);
 	free(ndbenv);
+	rdb->db_dbenv = 0;
     }
-    rdb->db_dbenv = 0;
 }
 
 static struct ndbEnv_s *openEnv(rpmdb rdb)
-- 
2.27.0

