From 92de1c2c820816801681d76f5de7137a2b5996df Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 21 Jul 2015 10:49:54 -0700 Subject: [PATCH] remove unnecessary checks for NULL before free Since free(NULL) is a no-op, it is safe to remove unnecesary if checks. --- misc/lnstat_util.c | 3 +-- misc/ss.c | 12 ++++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/misc/lnstat_util.c b/misc/lnstat_util.c index 9492baf02..6dde7c494 100644 --- a/misc/lnstat_util.c +++ b/misc/lnstat_util.c @@ -322,8 +322,7 @@ struct lnstat_field *lnstat_find_field(struct lnstat_file *lnstat_files, } } out: - if (file) - free(file); + free(file); return ret; } diff --git a/misc/ss.c b/misc/ss.c index 6abd1d120..17ec21603 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -1994,8 +1994,7 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r, s.segs_out = info->tcpi_segs_out; s.segs_in = info->tcpi_segs_in; tcp_stats_print(&s); - if (s.dctcp) - free(s.dctcp); + free(s.dctcp); } } @@ -2380,8 +2379,7 @@ static int tcp_show(struct filter *f, int socktype) outerr: do { int saved_errno = errno; - if (buf) - free(buf); + free(buf); if (fp) fclose(fp); errno = saved_errno; @@ -2514,8 +2512,7 @@ static void unix_list_free(struct sockstat *list) list = list->next; - if (name) - free(name); + free(name); free(s); } } @@ -2679,8 +2676,7 @@ static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh, if (show_mem || show_details) printf("\n"); - if (name) - free(name); + free(name); return 0; } -- 2.47.2