From: Karel Zak Date: Thu, 25 Oct 2007 20:10:07 +0000 (+0200) Subject: setterm: opened file leaving unclosed X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40e147a933b0b0664ffd5b7081a6b367bbedd46e;p=util-linux setterm: opened file leaving unclosed Co-Author: lizf Signed-off-by: Karel Zak --- diff --git a/misc-utils/setterm.c b/misc-utils/setterm.c index 5d889ea4..ebf7f0ac 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= 0) + close(fd); exit(1); }