summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-21 15:55:33 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-21 15:55:33 -0700
commita30892ed9b6d193f6eb2bab5b37180ac8f63b0b1 (patch)
tree5ec3a15a48c0d8f3796de2fc4a999ae22a4595cd
parent26fb314644fd01928fc881e72e36b2c6bdda5b3b (diff)
downloadxorg-lib-libXaw-a30892ed9b6d193f6eb2bab5b37180ac8f63b0b1.tar.gz
Fix fd leak when write() fails in WriteToFile()
Reported by parfait 1.1 bug checking tool: File Descriptor Leak: Leaked File Descriptor fd at line 1098 of src/MultiSrc.c in function 'WriteToFile'. fd initialized at line 1096 with creat fd leaks when creat(name, 438) != -1 at line 1096. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--src/MultiSrc.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/MultiSrc.c b/src/MultiSrc.c
index 33aa06a..efa08b0 100644
--- a/src/MultiSrc.c
+++ b/src/MultiSrc.c
@@ -1092,15 +1092,18 @@ static Bool
WriteToFile(String string, String name)
{
int fd;
+ Bool result = True;
- if (((fd = creat(name, 0666)) == -1)
- || (write(fd, string, strlen(string)) == -1))
+ if ((fd = creat(name, 0666)) == -1)
return (False);
+ if (write(fd, string, strlen(string)) == -1)
+ result = False;
+
if (close(fd) == -1)
return (False);
- return (True);
+ return (result);
}