lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date: Wed, 10 May 2023 08:20:42 -0700
From: Stephen Hemminger <stephen@...workplumber.org>
To: netdev@...r.kernel.org
Cc: Stephen Hemminger <stephen@...workplumber.org>
Subject: [PATCH iproute2] remove unnecessary checks for NULL before calling free()

The function free() handles the case wher argument is NULL
by doing nothing. So the extra checks are not needed.

Found by modified version of kernel coccinelle script.

Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
---
 ip/ipnexthop.c | 9 +++------
 lib/utils.c    | 3 +--
 tc/m_ipt.c     | 3 +--
 tc/m_xt.c      | 3 +--
 tc/m_xt_old.c  | 3 +--
 tc/tc_qdisc.c  | 3 +--
 6 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index 9f16b8097b40..894f2a126f40 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -345,10 +345,8 @@ static void print_nh_res_bucket(FILE *fp, const struct rtattr *res_bucket_attr)
 
 static void ipnh_destroy_entry(struct nh_entry *nhe)
 {
-	if (nhe->nh_encap)
-		free(nhe->nh_encap);
-	if (nhe->nh_groups)
-		free(nhe->nh_groups);
+	free(nhe->nh_encap);
+	free(nhe->nh_groups);
 }
 
 /* parse nhmsg into nexthop entry struct which must be destroyed by
@@ -586,8 +584,7 @@ static struct nh_entry *ipnh_cache_add(__u32 nh_id)
 	ipnh_cache_link_entry(nhe);
 
 out:
-	if (answer)
-		free(answer);
+	free(answer);
 
 	return nhe;
 
diff --git a/lib/utils.c b/lib/utils.c
index b740531ab6c9..8dc302bdfe02 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1707,8 +1707,7 @@ int do_batch(const char *name, bool force,
 		}
 	}
 
-	if (line)
-		free(line);
+	free(line);
 
 	return ret;
 }
diff --git a/tc/m_ipt.c b/tc/m_ipt.c
index 465d1b8073d0..3fe70faf2ec6 100644
--- a/tc/m_ipt.c
+++ b/tc/m_ipt.c
@@ -412,8 +412,7 @@ static int parse_ipt(struct action_util *a, int *argc_p,
         m->tflags = 0;
         m->used = 0;
 	/* Free allocated memory */
-	if (m->t)
-	    free(m->t);
+	free(m->t);
 
 
 	return 0;
diff --git a/tc/m_xt.c b/tc/m_xt.c
index 8a6fd3ce0ffc..658084378124 100644
--- a/tc/m_xt.c
+++ b/tc/m_xt.c
@@ -299,8 +299,7 @@ static int parse_ipt(struct action_util *a, int *argc_p,
 		m->tflags = 0;
 		m->used = 0;
 		/* Free allocated memory */
-		if (m->t)
-			free(m->t);
+		free(m->t);
 	}
 
 	return 0;
diff --git a/tc/m_xt_old.c b/tc/m_xt_old.c
index efa084c5441b..7c6b79b99af5 100644
--- a/tc/m_xt_old.c
+++ b/tc/m_xt_old.c
@@ -337,8 +337,7 @@ static int parse_ipt(struct action_util *a, int *argc_p,
         m->tflags = 0;
         m->used = 0;
 	/* Free allocated memory */
-	if (m->t)
-	    free(m->t);
+	free(m->t);
 
 
 	return 0;
diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c
index 92ceb4c2f980..129ad9d96f8d 100644
--- a/tc/tc_qdisc.c
+++ b/tc/tc_qdisc.c
@@ -187,8 +187,7 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)
 			addattr_l(&req.n, sizeof(req), TCA_STAB_DATA, stab.data,
 				  stab.szopts.tsize * sizeof(__u16));
 		addattr_nest_end(&req.n, tail);
-		if (stab.data)
-			free(stab.data);
+		free(stab.data);
 	}
 
 	if (d[0])  {
-- 
2.39.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ