From 14b3c0f0afe691739cdfc71d71adf740114d5a98 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 3 Nov 2021 18:27:12 +0100
Subject: [PATCH] event/Loop: destruct the Uring::Manager in the destructor
 before assert()

Fixes assertion failure when the EventLoop gets destructed before
Run() was ever called.

Fixes https://bugs.debian.org/998310
---
 NEWS               | 1 +
 src/event/Loop.cxx | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/NEWS b/NEWS
index ebaa35404..be86b0f16 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,5 @@
 ver 0.23.4 (not yet released)
+* fix crash or debug builds if startup fails
 
 ver 0.23.3 (2021/10/31)
 * protocol
diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx
index 31049a057..cfc136a5c 100644
--- a/src/event/Loop.cxx
+++ b/src/event/Loop.cxx
@@ -52,6 +52,13 @@ EventLoop::EventLoop(
 
 EventLoop::~EventLoop() noexcept
 {
+#if defined(HAVE_URING) && !defined(NDEBUG)
+	/* if Run() was never called (maybe because startup failed and
+	   an exception is pending), we need to destruct the
+	   Uring::Manager here or else the assertions below fail */
+	uring.reset();
+#endif
+
 	assert(defer.empty());
 	assert(idle.empty());
 #ifdef HAVE_THREADED_EVENT_LOOP