Avoid core dump on
Nick Ing-Simmons [Fri, 20 Apr 2001 18:28:35 +0000 (18:28 +0000)]
   open(STDOUT,">",\$foo);

p4raw-id: //depot/perlio@9766

doio.c

diff --git a/doio.c b/doio.c
index 631149d..f65f286 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -555,7 +555,10 @@ Perl_do_openn(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
        if (savefd != fd) {
            Pid_t pid;
            SV *sv;
-           PerlLIO_dup2(fd, savefd);
+           if (PerlLIO_dup2(fd, savefd) < 0) {
+               (void)PerlIO_close(fp);
+               goto say_false;
+           }
 #ifdef VMS
            if (savefd != PerlIO_fileno(PerlIO_stdin())) {
              char newname[FILENAME_MAX+1];