From: Xiao Ni Date: Fri, 26 Jul 2024 07:14:11 +0000 (+0800) Subject: mdadm/mdstat: fix coverity issue CHECKED_RETURN X-Git-Tag: mdadm-4.4~102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6984814b6fd879efae178acb057c1025aa4c64e8;p=thirdparty%2Fmdadm.git mdadm/mdstat: fix coverity issue CHECKED_RETURN It needs to check return values when functions return value. Signed-off-by: Xiao Ni Signed-off-by: Mariusz Tkaczyk --- diff --git a/mdstat.c b/mdstat.c index cbbace3d..a971a957 100644 --- a/mdstat.c +++ b/mdstat.c @@ -194,8 +194,11 @@ struct mdstat_ent *mdstat_read(int hold, int start) f = fopen("/proc/mdstat", "r"); if (f == NULL) return NULL; - else - fcntl(fileno(f), F_SETFD, FD_CLOEXEC); + + if (fcntl(fileno(f), F_SETFD, FD_CLOEXEC) < 0) { + fclose(f); + return NULL; + } all = NULL; end = &all; @@ -329,7 +332,10 @@ struct mdstat_ent *mdstat_read(int hold, int start) } if (hold && mdstat_fd == -1) { mdstat_fd = dup(fileno(f)); - fcntl(mdstat_fd, F_SETFD, FD_CLOEXEC); + if (fcntl(mdstat_fd, F_SETFD, FD_CLOEXEC) < 0) { + fclose(f); + return NULL; + } } fclose(f);