summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-21 15:18:28 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-21 15:18:28 -0700
commit93986e62c7793ef7bb3123748249302e974b72e6 (patch)
tree5bf201bcee4614afd305fefa80a337fd0863bf37
parent23371e39e595056b3db2e361fad8a21ed4a0d9e7 (diff)
Close file leak when fdopen() fails in OpenFile()
Found by parfait 1.1 bug checking tool: Error: File Leak File Descriptor Leak: Leaked File Descriptor fd at line 457 of app/xditview/Dvi.c in function 'OpenFile'. fd initialized at line 449 with mkstemp Also reorganize & clean up the code a bit while we're here Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--Dvi.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/Dvi.c b/Dvi.c
index 549efb4..9c4a502 100644
--- a/Dvi.c
+++ b/Dvi.c
@@ -434,22 +434,22 @@ CloseFile (DviWidget dw)
static void
OpenFile (DviWidget dw)
{
- char tmpName[sizeof ("/tmp/dviXXXXXX")];
-#ifdef HAS_MKSTEMP
- int fd;
-#endif
-
dw->dvi.tmpFile = NULL;
if (!dw->dvi.seek) {
- strcpy (tmpName, "/tmp/dviXXXXXX");
+ char tmpName[] = "/tmp/dviXXXXXX";
+
#ifndef HAS_MKSTEMP
mktemp (tmpName);
dw->dvi.tmpFile = fopen (tmpName, "w+");
#else
- fd = mkstemp(tmpName);
- dw->dvi.tmpFile = fdopen(fd, "w+");
+ int fd = mkstemp(tmpName);
+ if (fd != -1) {
+ dw->dvi.tmpFile = fdopen(fd, "w+");
+ if (dw->dvi.tmpFile == NULL)
+ close(fd);
+ }
#endif
- unlink (tmpName);
+ remove (tmpName);
}
if (dw->dvi.requested_page < 1)
dw->dvi.requested_page = 1;