ref: 13538a0f7d8fca824ce4522a41c7a68bf83e5507
parent: 51448dbce0dba91459a7537cd5870f44398fd450
author: robs <robs>
date: Mon Jul 21 14:34:08 EDT 2008
fix [2017865] fclose should be pclose in some cases
--- a/src/formats.c
+++ b/src/formats.c
@@ -340,8 +340,18 @@
return *text == ':';
}
-static FILE * xfopen(char const * identifier, char const * mode)
+static int xfclose(FILE * file, sox_bool is_process)
{
+ return
+#ifdef HAVE_POPEN
+ is_process? pclose(file) :
+#endif
+ fclose(file);
+}
+
+static FILE * xfopen(char const * identifier, char const * mode, sox_bool * is_process)
+{
+ *is_process = sox_false;
if (is_uri(identifier)) {
FILE * f = NULL;
#ifdef HAVE_POPEN
@@ -350,6 +360,7 @@
sprintf(command, command_format, identifier);
f = popen(command, "r");
free(command);
+ *is_process = sox_true;
#else
sox_fail("open URL support has not been built into SoX");
#endif
@@ -388,7 +399,7 @@
SET_BINARY_MODE(stdin);
ft->fp = stdin;
}
- else if ((ft->fp = xfopen(path, "rb")) == NULL) {
+ else if ((ft->fp = xfopen(path, "rb", &ft->is_process)) == NULL) {
sox_fail("can't open input file `%s': %s", path, strerror(errno));
goto error;
}
@@ -423,7 +434,7 @@
}
ft->handler = *handler;
if (ft->handler.flags & SOX_FILE_NOSTDIO) {
- fclose(ft->fp);
+ xfclose(ft->fp, ft->is_process);
ft->fp = NULL;
}
}
@@ -462,7 +473,7 @@
error:
if (ft->fp && ft->fp != stdin)
- fclose(ft->fp);
+ xfclose(ft->fp, ft->is_process);
free(ft->priv);
free(ft->filename);
free(ft->filetype);
@@ -764,7 +775,7 @@
error:
if (ft->fp && ft->fp != stdout)
- fclose(ft->fp);
+ xfclose(ft->fp, ft->is_process);
free(ft->priv);
free(ft->filename);
free(ft->filetype);
@@ -804,7 +815,7 @@
}
if (ft->fp && ft->fp != stdin && ft->fp != stdout)
- fclose(ft->fp);
+ xfclose(ft->fp, ft->is_process);
free(ft->filename);
free(ft->filetype);
sox_delete_comments(&ft->oob.comments);
@@ -846,7 +857,8 @@
char * text = lsx_malloc(text_length + 1);
char * dirname = lsx_strdup(listname);
char * slash_pos = LAST_SLASH(dirname);
- FILE * file = xfopen(listname, "r");
+ sox_bool is_process;
+ FILE * file = xfopen(listname, "r", &is_process);
char * filename;
int c, result = SOX_SUCCESS;
@@ -911,7 +923,7 @@
sox_fail("error reading playlist file `%s': %s", listname, strerror(errno));
result = SOX_EOF;
}
- fclose(file);
+ xfclose(file, is_process);
}
free(text);
free(dirname);
--- a/src/sox.h
+++ b/src/sox.h
@@ -369,6 +369,7 @@
int sox_errno; /* Failure error code */
char sox_errstr[256]; /* Failure error text */
FILE * fp; /* File stream pointer */
+ sox_bool is_process; /* True/false if fp is from popen/fopen */
long tell_off;
long data_start;
sox_format_handler_t handler; /* Format handler for this file */