From c05f86af93b00c51b3a5154d7d4db484394027f2 Mon Sep 17 00:00:00 2001 From: oilbeater Date: Tue, 28 Mar 2023 10:30:24 +0000 Subject: [PATCH] fix: memory leak in IPAM caused by leftover map keys When all nics are popped from the list the map key still exist which will lead memory leak each time a pod is deleted. --- pkg/ipam/subnet.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/ipam/subnet.go b/pkg/ipam/subnet.go index 7a1694572f4..ce56ee6d327 100644 --- a/pkg/ipam/subnet.go +++ b/pkg/ipam/subnet.go @@ -171,6 +171,9 @@ func (subnet *Subnet) pushPodNic(podName, nicName string) { func (subnet *Subnet) popPodNic(podName, nicName string) { subnet.PodToNicList[podName] = util.RemoveString(subnet.PodToNicList[podName], nicName) + if subnet.PodToNicList[podName] == nil { + delete(subnet.PodToNicList, podName) + } } func (subnet *Subnet) GetRandomAddress(podName, nicName string, mac string, skippedAddrs []string, checkConflict bool) (IP, IP, string, error) {