freebsd-ports/lang/gawk/files/patch-io.c
Kirill Ponomarev 53381205a1 Fix coredump while running with nonexistent files.
PR:		ports/115014
Submitted by:	Kirill Nuzhdin <kirill@rad.chem.msu.ru>
2007-09-03 20:18:36 +00:00

29 lines
482 B
C

$FreeBSD$
--- io.c.orig
+++ io.c
@@ -2480,9 +2480,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 +2498,8 @@
}
if (iop->fd == INVALID_HANDLE) {
- free(iop);
+ if (iop_malloced)
+ free(iop);
return NULL;
}
if (isatty(iop->fd))