From 8f4092733b9b3ba815597e67fc20c9e1897803e5 Mon Sep 17 00:00:00 2001 From: Petr Sabata Date: Fri, 1 Apr 2011 00:21:34 +0000 Subject: [PATCH 16/16] fcoe-utils: Avoid freeing uninitialized pointer in fcoe_find_fchost() Currently, running fcoeadm -i when SYSFS_FCHOST path isn't available results in fcoeadm crash. This patch checks for this and frees namelist only if it's been initialized. Signed-off-by: Petr Sabata Signed-off-by: Robert Love --- lib/fcoe_utils.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fcoe_utils.c b/lib/fcoe_utils.c index 142b045..d54cd4d 100644 --- a/lib/fcoe_utils.c +++ b/lib/fcoe_utils.c @@ -67,11 +67,11 @@ static int fcoe_check_fchost(const char *ifname, const char *dname) enum fcoe_status fcoe_find_fchost(char *ifname, char *fchost, int len) { - int n, dname_len; + int n, dname_len, status; struct dirent **namelist; int rc = ENOFCOECONN; - n = scandir(SYSFS_FCHOST, &namelist, 0, alphasort); + status = n = scandir(SYSFS_FCHOST, &namelist, 0, alphasort); for (n-- ; n >= 0 ; n--) { if (rc) { @@ -94,9 +94,9 @@ enum fcoe_status fcoe_find_fchost(char *ifname, char *fchost, int len) } } free(namelist[n]); - } - free(namelist); + if (status >= 0) + free(namelist); return rc; } -- 1.7.4.4