@@ -146,8 +146,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;
@@ -281,7 +284,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);
It needs to check return values when functions return value. Signed-off-by: Xiao Ni <xni@redhat.com> --- mdstat.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)