Also remove redundant close() of state_fd, since the fclose() of
state_f will result in the fd being closed.
Addresses-Coverity-Id: #
1049146
Addresses-Coverity-Id: #26092
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
state_fd = open("/var/lib/libuuid/clock.txt",
O_RDWR|O_CREAT, 0660);
(void) umask(save_umask);
- state_f = fdopen(state_fd, "r+");
- if (!state_f) {
- close(state_fd);
- state_fd = -1;
+ if (state_fd >= 0) {
+ state_f = fdopen(state_fd, "r+");
+ if (!state_f) {
+ close(state_fd);
+ state_fd = -1;
+ }
}
}
fl.l_type = F_WRLCK;
if ((errno == EAGAIN) || (errno == EINTR))
continue;
fclose(state_f);
- close(state_fd);
state_fd = -1;
break;
}
}
rewind(state_f);
fl.l_type = F_UNLCK;
- fcntl(state_fd, F_SETLK, &fl);
+ if (fcntl(state_fd, F_SETLK, &fl) < 0) {
+ fclose(state_f);
+ state_fd = -1;
+ }
}
*clock_high = clock_reg >> 32;