Dereference pointers when publishing (#7905)

This commit is contained in:
andig 2023-05-10 16:16:59 +02:00 • committed by GitHub
parent b97850afd0
commit 229a2d2b34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,7 @@
package util
import "reflect"
// TeeAttacher allows to attach a listener to a tee
type TeeAttacher interface {
Attach() <-chan Param
@ -28,6 +30,13 @@ func (t *Tee) add(out chan<- Param) {
func (t *Tee) Run(in <-chan Param) {
for msg := range in {
for _, recv := range t.recv {
// dereference pointers (https://github.com/evcc-io/evcc/issues/7895)
if val := reflect.ValueOf(msg.Val); val.Kind() == reflect.Ptr {
if ptr := reflect.Indirect(val); ptr.IsValid() {
msg.Val = ptr.Addr().Elem().Interface()
}
}
recv <- msg
}
}