summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-21 15:37:00 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-21 15:37:00 -0700
commit642d73c50ae19a55975919c84191da15b31608a4 (patch)
treee729664b0170ccd82441ce317366017f787b2d66
parent4ecaac617be1ef59be532671d07f062e52111f3a (diff)
Avoid fd leak when fdopen() fails in openFiles()
Found by parfait 1.1 bug checker: File Descriptor Leak: Leaked File Descriptor newfd at line 590 of xdm/auth.c in function 'openFiles'. newfd initialized at line 573 with open newfd leaks when newfd >= 0 at line 574. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--xdm/auth.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/xdm/auth.c b/xdm/auth.c
index fd6bc7d..068a643 100644
--- a/xdm/auth.c
+++ b/xdm/auth.c
@@ -571,8 +571,11 @@ openFiles (char *name, char *new_name, FILE **oldp, FILE **newp)
*/
(void) unlink (new_name);
newfd = open (new_name, O_WRONLY | O_CREAT | O_EXCL, 0600);
- if (newfd >= 0)
+ if (newfd >= 0) {
*newp = fdopen (newfd, "w");
+ if (*newp == NULL)
+ close(newfd);
+ }
else
{
LogError ("Cannot create file %s: %s\n", new_name,