summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-21 13:56:23 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-21 13:59:16 -0700
commit73be08929d1d418370ae235e5261e64f72054cbf (patch)
treec2884208502b2d61096533221ce909d72894ebb5
parent22a09b77093970423e721ebd8004a593d5f88a21 (diff)
Fix file leak if fdopen() fails
Reported by parfait 1.1: File Descriptor Leak: Leaked File Descriptor fd at line 313 of xconsole.c in function 'OpenConsole'. fd initialized at line 285 with open fd leaks when fd != -1 at line 287. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--xconsole.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/xconsole.c b/xconsole.c
index c29237e..67e81aa 100644
--- a/xconsole.c
+++ b/xconsole.c
@@ -277,20 +277,24 @@ OpenConsole(void)
}
else
{
- struct stat sbuf;
-
regularFile = FALSE;
if (access(app_resources.file, R_OK) == 0)
{
int fd = open (app_resources.file,
O_RDONLY | O_NONBLOCK | O_NOCTTY);
- if (fd != -1)
+ if (fd != -1) {
input = fdopen (fd, "r");
- if (input)
- if (!stat(app_resources.file, &sbuf) &&
- S_ISREG( sbuf.st_mode ) )
- regularFile = TRUE;
+ if (input) {
+ struct stat sbuf;
+
+ if (!stat(app_resources.file, &sbuf) &&
+ S_ISREG( sbuf.st_mode ) )
+ regularFile = TRUE;
+ }
+ else
+ close(fd);
+ }
}
}
if (!input)