--- io.c 2006/01/17 13:17:28 1.1 +++ io.c 2006/01/17 13:54:10 @@ -2479,8 +2479,9 @@ { struct stat sbuf; struct open_hook *oh; + int iopwasnull = iop == NULL; - if (iop == NULL) + if (iopwasnull) emalloc(iop, IOBUF *, sizeof(IOBUF), "iop_alloc"); memset(iop, '\0', sizeof(IOBUF)); iop->flag = 0; @@ -2494,7 +2495,7 @@ } if (iop->fd == INVALID_HANDLE) { - free(iop); + if (iopwasnull) free(iop); return NULL; } if (isatty(iop->fd))