shithub: sox

Download patch

ref: d68424fe69dec6bedd35bdaea03ecb3e7c3c6c1e
parent: dd8b63bdc2966c931b73d5f7a17db336cbec6c21
author: Nigel Kettlewell <njk@njknet.org.uk>
date: Tue Apr 19 12:02:19 EDT 2016

formats: release stdin/stdout reservation on close

Reset the stdin/out_in_use_by globals when closing the associated file,
letting stdin/out be opened again.  Without this, they remain blocked
forever once opened.

--- a/src/formats.c
+++ b/src/formats.c
@@ -1057,8 +1057,15 @@
     else result = ft->handler.stopwrite? (*ft->handler.stopwrite)(ft) : SOX_SUCCESS;
   }
 
-  if (ft->fp && ft->fp != stdin && ft->fp != stdout)
+  if (ft->fp == stdin) {
+    sox_globals.stdin_in_use_by = NULL;
+  } else if (ft->fp == stdout) {
+    fflush(stdout);
+    sox_globals.stdout_in_use_by = NULL;
+  } else if (ft->fp) {
     xfclose(ft->fp, ft->io_type);
+  }
+
   free(ft->priv);
   free(ft->filename);
   free(ft->filetype);