From c24589a5be98a9c0dac2280f78209f9147ad588a Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Tue, 9 Jul 2024 22:07:51 +0700 Subject: [PATCH] internal/clientinfo: avoid heap alloc with mdns read loop Once resource record (RR) was used to extract necessary information, it should be freed in memory. However, the current way that ctrld declare the RRs causing the slices to be heap allocated, and stay in memory longer than necessary. On system with low capacity, or firmware that GC does not run agressively, it may causes the system memory exhausted. To fix it, prevent RRs to be heap allocated, so they could be freed immediately after each iterations. --- internal/clientinfo/mdns.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/clientinfo/mdns.go b/internal/clientinfo/mdns.go index 3b539e9..3c8af6e 100644 --- a/internal/clientinfo/mdns.go +++ b/internal/clientinfo/mdns.go @@ -165,7 +165,7 @@ func (m *mdns) readLoop(conn *net.UDPConn) { } var ip, name string - rrs := make([]dns.RR, 0, len(msg.Answer)+len(msg.Extra)) + var rrs []dns.RR rrs = append(rrs, msg.Answer...) rrs = append(rrs, msg.Extra...) for _, rr := range rrs {