summaryrefslogtreecommitdiffhomepage
path: root/pkg/server/server.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@gmail.com>2019-08-05 13:19:28 +0900
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2019-08-05 13:34:43 +0900
commitda536952b3d12104bdcf9c0385970100b2aefe3e (patch)
treedbf780b1c63724938caf0d6591644b38d5f3bdd3 /pkg/server/server.go
parentfe95682cda718df260d76bf38883fa6a8c335ba8 (diff)
server: fix DeletePath() memory leak
DeletePath() doesn't delete the entry of the map for UUID. Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Diffstat (limited to 'pkg/server/server.go')
-rw-r--r--pkg/server/server.go25
1 files changed, 14 insertions, 11 deletions
diff --git a/pkg/server/server.go b/pkg/server/server.go
index d77512f5..30ccbc37 100644
--- a/pkg/server/server.go
+++ b/pkg/server/server.go
@@ -134,7 +134,7 @@ type BgpServer struct {
zclient *zebraClient
bmpManager *bmpClientManager
mrtManager *mrtManager
- uuidMap map[uuid.UUID]string
+ uuidMap map[string]uuid.UUID
}
func NewBgpServer(opt ...ServerOption) *BgpServer {
@@ -151,7 +151,7 @@ func NewBgpServer(opt ...ServerOption) *BgpServer {
roaManager: roaManager,
mgmtCh: make(chan *mgmtOp, 1),
watcherMap: make(map[watchEventType][]*watcher),
- uuidMap: make(map[uuid.UUID]string),
+ uuidMap: make(map[string]uuid.UUID),
}
s.bmpManager = newBmpClientManager(s)
s.mrtManager = newMrtManager(s)
@@ -2003,7 +2003,7 @@ func (s *BgpServer) AddPath(ctx context.Context, r *api.AddPathRequest) (*api.Ad
return err
}
if id, err := uuid.NewRandom(); err == nil {
- s.uuidMap[id] = pathTokey(path)
+ s.uuidMap[pathTokey(path)] = id
uuidBytes, _ = id.MarshalBinary()
}
return nil
@@ -2030,13 +2030,13 @@ func (s *BgpServer) DeletePath(ctx context.Context, r *api.DeletePathRequest) er
// Delete locally generated path which has the given UUID
path := func() *table.Path {
id, _ := uuid.FromBytes(r.Uuid)
- if key, ok := s.uuidMap[id]; !ok {
- return nil
- } else {
- for _, path := range s.globalRib.GetPathList(table.GLOBAL_RIB_NAME, 0, s.globalRib.GetRFlist()) {
- if path.IsLocal() && key == pathTokey(path) {
- delete(s.uuidMap, id)
- return path
+ for k, v := range s.uuidMap {
+ if v == id {
+ for _, path := range s.globalRib.GetPathList(table.GLOBAL_RIB_NAME, 0, s.globalRib.GetRFlist()) {
+ if path.IsLocal() && k == pathTokey(path) {
+ delete(s.uuidMap, k)
+ return path
+ }
}
}
}
@@ -2058,12 +2058,15 @@ func (s *BgpServer) DeletePath(ctx context.Context, r *api.DeletePathRequest) er
deletePathList = append(deletePathList, path.Clone(true))
}
}
- s.uuidMap = make(map[uuid.UUID]string)
+ s.uuidMap = make(map[string]uuid.UUID)
} else {
if err := s.fixupApiPath(r.VrfId, pathList); err != nil {
return err
}
deletePathList = pathList
+ for _, p := range deletePathList {
+ delete(s.uuidMap, pathTokey(p))
+ }
}
s.propagateUpdate(nil, deletePathList)
return nil