FILE's closed in ERR state are not marked as CLOSED and thus cannot be reused. Reference: /n/sources/patch/applied/stdio.file.leak Date: Wed Dec 7 16:52:22 CET 2005 --- /sys/src/ape/lib/ap/stdio/sclose.c Wed Dec 7 16:51:10 2005 +++ /sys/src/ape/lib/ap/stdio/sclose.c Wed Dec 7 16:51:07 2005 @@ -9,6 +9,7 @@ default: /* ERR CLOSED */ if(f->buf && f->flags&BALLOC) free(f->buf); + f->state=CLOSED; f->flags=0; return NULL; case OPEN: