diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-04-21 13:56:23 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-04-21 13:59:16 -0700 |
commit | 73be08929d1d418370ae235e5261e64f72054cbf (patch) | |
tree | c2884208502b2d61096533221ce909d72894ebb5 | |
parent | 22a09b77093970423e721ebd8004a593d5f88a21 (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.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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) |