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 <[email protected]>
---
 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 0ebdf9b..66e616f 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

_______________________________________________
devel mailing list
[email protected]
https://lists.open-fcoe.org/mailman/listinfo/devel

Reply via email to