Index: sed-4.2.2/sed/utils.c =================================================================== --- sed-4.2.2.orig/sed/utils.c +++ sed-4.2.2/sed/utils.c @@ -299,6 +299,7 @@ ck_fclose(stream) if (!stream || stream == cur->fp) { prev->link = cur->link; + open_files = r.link; do_ck_fclose (cur->fp); free(cur->name); free(cur); @@ -307,8 +308,6 @@ ck_fclose(stream) prev = cur; } - open_files = r.link; - /* Also care about stdout, because if it is redirected the last output operations might fail and it is important to signal this as an error (perhaps to make). */