This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fd closes for failure paths.
authorJarkko Hietaniemi <jhi@iki.fi>
Wed, 7 May 2014 13:30:35 +0000 (09:30 -0400)
committerTony Cook <tony@develop-help.com>
Thu, 29 May 2014 04:46:52 +0000 (14:46 +1000)
Fix for Coverity perl5 CIDs 29053, 29055, 29057: Resource leak (RESOURCE_LEAK)
leaked_handle: Handle variable fd going out of scope leaks the handle.

perlio.c

index f110759..aa9a932 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -2661,6 +2661,7 @@ PerlIOUnix_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers,
        }
        if (!PerlIOValid(f)) {
            if (!(f = PerlIO_push(aTHX_ f, self, mode, PerlIOArg))) {
+               PerlLIO_close(fd);
                return NULL;
            }
        }
@@ -2696,6 +2697,7 @@ PerlIOUnix_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags)
            PerlIOUnix_setfd(aTHX_ f, fd, os->oflags);
            return f;
        }
+        PerlLIO_close(fd);
     }
     return NULL;
 }
@@ -3050,6 +3052,7 @@ PerlIOStdio_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers,
                }
                return f;
            }
+            PerlLIO_close(fd);
        }
     }
     return NULL;