summaryrefslogtreecommitdiff
path: root/src/MultiSrc.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-21 15:55:33 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2018-09-30 15:06:20 -0700
commitb1745c3eb4f84c2b68a90cbec6f6a9255ece4645 (patch)
tree3cac8259fbeded707c996bd478856426594f0ad0 /src/MultiSrc.c
parente18ef34ee7694b9b423684eff1ed040859e4cd53 (diff)
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. (Adapted from libXaw commit a30892ed9b6d193f6eb2bab5b37180ac8f63b0b1.) Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'src/MultiSrc.c')
-rw-r--r--src/MultiSrc.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/MultiSrc.c b/src/MultiSrc.c
index 7ad3cdd..a1b2035 100644
--- a/src/MultiSrc.c
+++ b/src/MultiSrc.c
@@ -966,15 +966,18 @@ static Boolean
WriteToFile(String string, String name)
{
int fd;
+ Bool result = True;
- if ( ((fd = creat(name, 0666)) == -1 ) ||
- (write(fd, string, sizeof(unsigned char) * strlen(string)) == -1) )
+ if ((fd = creat(name, 0666)) == -1)
return(FALSE);
+ if (write(fd, string, sizeof(unsigned char) * strlen(string)) == -1)
+ result = False;
+
if ( close(fd) == -1 )
return(FALSE);
- return(TRUE);
+ return(result);
}