configuration: ignore an empty configuration struct in setConfiguration (#21)
If the plugin leaves the configuration struct empty, go will optimize away allocations of the zero-width struct failing the `setConfiguration` check that prevents a user from introducing race conditions.
This commit is contained in:
parent
b303e8da00
commit
76ba0b57a7
1 changed files with 9 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
@ -53,6 +55,13 @@ func (p *Plugin) setConfiguration(configuration *configuration) {
|
|||
defer p.configurationLock.Unlock()
|
||||
|
||||
if configuration != nil && p.configuration == configuration {
|
||||
// Ignore assignment if the configuration struct is empty. Go will optimize the
|
||||
// allocation for same to point at the same memory address, breaking the check
|
||||
// above.
|
||||
if reflect.ValueOf(*configuration).NumField() == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
panic("setConfiguration called with the existing configuration")
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue