[svn:parrot] r44711 - trunk/src/io

chromatic at svn.parrot.org chromatic at svn.parrot.org
Sat Mar 6 22:28:32 UTC 2010


Author: chromatic
Date: Sat Mar  6 22:28:25 2010
New Revision: 44711
URL: https://trac.parrot.org/parrot/changeset/44711

Log:
[IO] Worked around attempts to close unopened file descriptors in
Parrot_io_open_unix() (Coverity CID #168).

Modified:
   trunk/src/io/unix.c

Modified: trunk/src/io/unix.c
==============================================================================
--- trunk/src/io/unix.c	Sat Mar  6 22:07:56 2010	(r44710)
+++ trunk/src/io/unix.c	Sat Mar  6 22:28:25 2010	(r44711)
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2009, Parrot Foundation.
+Copyright (C) 2001-2010, Parrot Foundation.
 $Id$
 
 =head1 NAME
@@ -181,17 +181,19 @@
          */
         if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) {
             close(fd);
-            Parrot_str_free_cstring(spath); /* returning before C string freed */
+
+            /* returning before C string freed */
+            Parrot_str_free_cstring(spath);
             return PMCNULL;
         }
-        /*
-         * Check for truncate?
-         */
+
+        /* Check for truncate?  */
         if (oflags & O_TRUNC) {
             int tfd;
             while ((tfd = creat(spath, PIO_DEFAULTMODE)) < 0 && errno == EINTR)
                 errno = 0;
-            close(tfd);
+            if (tfd > 0)
+                close(tfd);
         }
     }
     else if (oflags & O_CREAT) {
@@ -199,10 +201,10 @@
         while ((fd = creat(spath, PIO_DEFAULTMODE)) < 0 && errno == EINTR)
             errno = 0;
         if (!(oflags & O_WRONLY)) {
-            close(fd);
-            /*
-             * File created, reopen with read+write
-             */
+            if (fd > 0)
+                close(fd);
+
+            /* File created, reopen with read+write */
             while ((fd = open(spath, oflags & (O_WRONLY | O_RDWR),
                               DEFAULT_OPEN_MODE)) < 0 && errno == EINTR)
                 errno = 0;


More information about the parrot-commits mailing list