From 8fdd021ed7904a8150b3940765d4dfffff3a00d7 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Mon, 1 Feb 2021 19:33:45 +0300 Subject: [PATCH] Pull request: dnsforward: fix closing of uninitialized ipset ctx Merge in DNS/adguard-home from fix-close to master Squashed commit of the following: commit 43b55105cc669e2740ef178808c81a22c8f53cc1 Author: Ainar Garipov Date: Mon Feb 1 19:19:12 2021 +0300 dnsforward: fix closing of uninitialized ipset ctx --- internal/dnsforward/ipset_linux.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/dnsforward/ipset_linux.go b/internal/dnsforward/ipset_linux.go index cf6a570f..e88c3986 100644 --- a/internal/dnsforward/ipset_linux.go +++ b/internal/dnsforward/ipset_linux.go @@ -192,14 +192,18 @@ func (c *ipsetCtx) init(ipsetConfig []string) (err error) { // Close closes the Linux Netfilter connections. func (c *ipsetCtx) Close() (err error) { var errors []error - err = c.ipv4Conn.Close() - if err != nil { - errors = append(errors, err) + if c.ipv4Conn != nil { + err = c.ipv4Conn.Close() + if err != nil { + errors = append(errors, err) + } } - err = c.ipv6Conn.Close() - if err != nil { - errors = append(errors, err) + if c.ipv6Conn != nil { + err = c.ipv6Conn.Close() + if err != nil { + errors = append(errors, err) + } } if len(errors) != 0 {