etw: Fix panic when provider creation fails

There is a cleanup function deferred to remove the provider from the global
provider map. However, this function didn't bind the value of provider ahead of
time, so when the provider creation returned with nil for provider, we tried to
cleanup a nil provider, and panicked.
This commit is contained in:
Kevin Parsons
2019-04-19 10:43:53 -07:00
parent 84b4ab48a5
commit dac77d8a7c
+2 -2
View File
@@ -130,11 +130,11 @@ func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (pro
})
provider = providers.newProvider()
defer func() {
defer func(provider *Provider) {
if err != nil {
providers.removeProvider(provider)
}
}()
}(provider)
provider.ID = id
provider.callback = callback