According to https://developer.apple.com/documentation/dnssd/1804733-dnsserviceregister the DNSServiceRef is initialized only if DNSServiceRegister() returns kDNSServiceErr_NoError. The faulty error handling code could therefore crash.