Skip to content

Commit

Permalink
Clone router map before returning it to user (#497)
Browse files Browse the repository at this point in the history
* Clone router map before returning it to user
  • Loading branch information
HRogge authored Oct 26, 2023
1 parent 38e3fa4 commit a48812e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mux/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"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"
"golang.org/x/exp/maps" // TODO: switch to non-exp maps package when dependency hits 1.20
)

type ResponseWriter = interface {
Expand Down Expand Up @@ -201,7 +202,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 a48812e

Please sign in to comment.