diff --git a/internal/brokers/manager.go b/internal/brokers/manager.go index 21a45cf8f..6d5bc126f 100644 --- a/internal/brokers/manager.go +++ b/internal/brokers/manager.go @@ -40,10 +40,17 @@ func NewManager(ctx context.Context, brokersConfPath string, configuredBrokers [ brokersConfPathWithExample, cleanup, err := useExampleBrokers() if err != nil { return nil, err - } else if brokersConfPathWithExample != "" { + } + if brokersConfPathWithExample != "" { brokersConfPath = brokersConfPathWithExample } + defer func() { + if err != nil && cleanup != nil { + cleanup() + } + }() + // Connect to the system bus // Don't call dbus.SystemBus which caches globally system dbus (issues in tests) bus, err := dbus.ConnectSystemBus()