From fb70f9393513908ee1b7267d24452ec2b9300b1c Mon Sep 17 00:00:00 2001 From: Oilbeater Date: Wed, 29 Mar 2023 09:27:33 +0800 Subject: [PATCH] fix: memory leak in IPAM caused by leftover map keys (#2566) When all nics are popped from the list the map key still exist which will lead memory leak each time a pod is deleted. (cherry picked from commit 3f7997b319083e1f0b87a1739804849f299a6c2a) --- pkg/ipam/subnet.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/ipam/subnet.go b/pkg/ipam/subnet.go index 3d6d978067b..a0fd1aa390a 100644 --- a/pkg/ipam/subnet.go +++ b/pkg/ipam/subnet.go @@ -159,6 +159,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) {