[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: /dev/fd/n bug in gawk 3.1.5
From: |
Aharon Robbins |
Subject: |
Re: /dev/fd/n bug in gawk 3.1.5 |
Date: |
Sat, 17 Jun 2006 23:20:13 +0300 |
Greetings. Re this:
> Date: Tue, 13 Jun 2006 17:49:58 -0700
> From: "John H. DuBois III" <address@hidden>
> Subject: /dev/fd/n bug in gawk 3.1.5
> To: address@hidden
>
> $ cat /dev/fd/4 /dev/fd/5 4<tm1 5<tm2
> Contents of tm1
> Contents of tm2
> $ gawk 1 /dev/fd/4 /dev/fd/5 4<tm1 5<tm2
> Contents of tm1
> Contents of tm1
>
>
> gawk: (FILENAME=/dev/fd/5 FNR=3) fatal: error reading input file `/dev/fd/4':
> Bad file number
Thanks for this bug report. The following patch fixes the problem. It includes
an
earlier patch to io.c as well.
The critical part of the patch is the change to the assignments to iop->flag.
Thanks,
Arnold
----------------- cut here -----------------------
--- ../gawk-3.1.5/io.c 2005-07-26 21:07:43.000000000 +0300
+++ io.c 2006-06-17 23:09:59.275743240 +0300
@@ -1440,7 +1440,7 @@
iop->end = iop->buf + len;
iop->dataend = iop->end;
iop->fd = -1;
- iop->flag = IOP_IS_INTERNAL | IOP_AT_START;
+ iop->flag = IOP_IS_INTERNAL | IOP_AT_START | IOP_NO_FREE;
}
/* specfdopen --- open an fd special file */
@@ -1454,15 +1454,12 @@
fd = devopen(name, mode);
if (fd == INVALID_HANDLE)
return INVALID_HANDLE;
- tp = iop_alloc(fd, name, NULL);
+ tp = iop_alloc(fd, name, iop);
if (tp == NULL) {
/* don't leak fd's */
close(fd);
return INVALID_HANDLE;
}
- *iop = *tp;
- iop->flag |= IOP_NO_FREE;
- free(tp);
return 0;
}
@@ -2480,9 +2477,12 @@
{
struct stat sbuf;
struct open_hook *oh;
+ int iop_malloced = FALSE;
- if (iop == NULL)
+ if (iop == NULL) {
emalloc(iop, IOBUF *, sizeof(IOBUF), "iop_alloc");
+ iop_malloced = TRUE;
+ }
memset(iop, '\0', sizeof(IOBUF));
iop->flag = 0;
iop->fd = fd;
@@ -2495,7 +2495,8 @@
}
if (iop->fd == INVALID_HANDLE) {
- free(iop);
+ if (iop_malloced)
+ free(iop);
return NULL;
}
if (isatty(iop->fd))