diff options
author | Karel Zak | 2007-10-25 22:10:07 +0200 |
---|---|---|
committer | Karel Zak | 2007-10-26 01:02:45 +0200 |
commit | 40e147a933b0b0664ffd5b7081a6b367bbedd46e (patch) | |
tree | 71fdd81b9a662ae69cb895a55d9fb4558a18dfb9 /misc-utils/setterm.c | |
parent | agetty: ungettextize several debugging messages. (diff) | |
download | kernel-qcow2-util-linux-40e147a933b0b0664ffd5b7081a6b367bbedd46e.tar.gz kernel-qcow2-util-linux-40e147a933b0b0664ffd5b7081a6b367bbedd46e.tar.xz kernel-qcow2-util-linux-40e147a933b0b0664ffd5b7081a6b367bbedd46e.zip |
setterm: opened file leaving unclosed
Co-Author: lizf <lizf@cn.fujitsu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/setterm.c')
-rw-r--r-- | misc-utils/setterm.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/misc-utils/setterm.c b/misc-utils/setterm.c index 5d889ea4f..ebf7f0ac7 100644 --- a/misc-utils/setterm.c +++ b/misc-utils/setterm.c @@ -1133,24 +1133,22 @@ screendump(int vcnum, FILE *F) { } if (fd < 0) { sprintf(infile, "/dev/vcsa%d", vcnum); - goto error; + goto read_error; } if (read(fd, header, 4) != 4) - goto error; + goto read_error; rows = header[0]; cols = header[1]; if (rows * cols == 0) - goto error; + goto read_error; inbuf = malloc(rows*cols*2); outbuf = malloc(rows*(cols+1)); if(!inbuf || !outbuf) { fputs(_("Out of memory"), stderr); - exit(1); - } - if (read(fd, inbuf, rows*cols*2) != rows*cols*2) { - fprintf(stderr, _("Error reading %s\n"), infile); - exit(1); + goto error; } + if (read(fd, inbuf, rows*cols*2) != rows*cols*2) + goto read_error; p = inbuf; q = outbuf; for(i=0; i<rows; i++) { @@ -1164,12 +1162,16 @@ screendump(int vcnum, FILE *F) { } if (fwrite(outbuf, 1, q-outbuf, F) != q-outbuf) { fprintf(stderr, _("Error writing screendump\n")); - exit(1); + goto error; } + close(fd); return; -error: +read_error: fprintf(stderr, _("Couldn't read %s\n"), infile); +error: + if (fd >= 0) + close(fd); exit(1); } |