diff options
author | Karel Zak | 2015-08-05 11:32:59 +0200 |
---|---|---|
committer | Karel Zak | 2015-08-05 11:33:29 +0200 |
commit | 6b497c0e19145cb3a70637c9d27c430b4602f8c0 (patch) | |
tree | 9cb18654c755f5ec1fa2769d95c781d1fc9f2d7c /sys-utils/rtcwake.c | |
parent | sfdisk: clarification for sfdisk man page (diff) | |
download | kernel-qcow2-util-linux-6b497c0e19145cb3a70637c9d27c430b4602f8c0.tar.gz kernel-qcow2-util-linux-6b497c0e19145cb3a70637c9d27c430b4602f8c0.tar.xz kernel-qcow2-util-linux-6b497c0e19145cb3a70637c9d27c430b4602f8c0.zip |
rtcwake: improve open() usage [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/rtcwake.c')
-rw-r--r-- | sys-utils/rtcwake.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c index 5dbacb247..842ea509c 100644 --- a/sys-utils/rtcwake.c +++ b/sys-utils/rtcwake.c @@ -242,19 +242,24 @@ static int setup_alarm(struct rtcwake_control *ctl, int fd, time_t *wakeup) static char **get_sys_power_states(struct rtcwake_control *ctl) { + int fd = -1; + if (!ctl->possible_modes) { - int fd; char buf[256] = { 0 }; - if (!(fd = open(SYS_POWER_STATE_PATH, O_RDONLY))) - return NULL; - if (read(fd, &buf, sizeof buf) < 0) { - close(fd); - return NULL; - } + fd = open(SYS_POWER_STATE_PATH, O_RDONLY); + if (fd < 0) + goto nothing; + if (read(fd, &buf, sizeof buf) <= 0) + goto nothing; ctl->possible_modes = strv_split(buf, " \n"); + close(fd); } return ctl->possible_modes; +nothing: + if (fd >= 0) + close(fd); + return NULL; } static void suspend_system(struct rtcwake_control *ctl) |