Skip to content

Commit

Permalink
Clone router map before returning it to user
Browse files Browse the repository at this point in the history
  • Loading branch information
HRogge authored and Danielius1922 committed Oct 18, 2023
1 parent 644ea5d commit a2c0657
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mux/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"io"
"sync"

// TODO: switch to non-exp maps package when dependency hits 1.20
"golang.org/x/exp/maps"

"github.com/plgd-dev/go-coap/v3/message"
"github.com/plgd-dev/go-coap/v3/message/codes"
"github.com/plgd-dev/go-coap/v3/message/pool"
Expand Down Expand Up @@ -196,7 +199,7 @@ func (r *Router) GetRoute(pattern string) *Route {
func (r *Router) GetRoutes() map[string]Route {
r.m.RLock()
defer r.m.RUnlock()
return r.z
return maps.Clone(r.z)
}

// ServeCOAP dispatches the request to the handler whose
Expand Down

0 comments on commit a2c0657

Please sign in to comment.