From ceb76b6a82b9c9bbc8933fc5d0f61b11f2109632 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 24 Feb 2021 14:00:31 +0100
Subject: [PATCH] zeroconf/Bonjour: pass a context pointer to the callback

---
 src/zeroconf/Bonjour.cxx | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/zeroconf/Bonjour.cxx b/src/zeroconf/Bonjour.cxx
index 524ab2e47..063177a07 100644
--- a/src/zeroconf/Bonjour.cxx
+++ b/src/zeroconf/Bonjour.cxx
@@ -88,7 +88,7 @@ RegisterBonjour(const char *name, const char *type, unsigned port,
 
 BonjourHelper::BonjourHelper(EventLoop &_loop, const char *name, unsigned port)
 	:service_ref(RegisterBonjour(name, SERVICE_TYPE, port,
-				     Callback, nullptr)),
+				     Callback, this)),
 	 socket_event(_loop,
 		      BIND_THIS_METHOD(OnSocketReady),
 		      SocketDescriptor(DNSServiceRefSockFD(service_ref)))
@@ -106,11 +106,13 @@ BonjourHelper::Callback([[maybe_unused]] DNSServiceRef sdRef,
 			[[maybe_unused]] const char *domain,
 			[[maybe_unused]] void *context) noexcept
 {
+	auto &helper = *(BonjourHelper *)context;
+
 	if (errorCode != kDNSServiceErr_NoError) {
 		LogError(bonjour_domain,
 			 "Failed to register zeroconf service");
 
-		bonjour_monitor->Cancel();
+		helper.Cancel();
 	} else {
 		FormatDebug(bonjour_domain,
 			    "Registered zeroconf service with name '%s'",