From bc97fa79b1b1d5e731f949d92d35d7ad839f1d35 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 15 Dec 2014 07:26:03 +0100 Subject: [PATCH] audio/flacdec: fix pcmconv pipeline race (thanks mischief and henesy) --- sys/src/cmd/audio/flacdec/flacdec.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sys/src/cmd/audio/flacdec/flacdec.c b/sys/src/cmd/audio/flacdec/flacdec.c index 614f472a8..f2a530db7 100644 --- a/sys/src/cmd/audio/flacdec/flacdec.c +++ b/sys/src/cmd/audio/flacdec/flacdec.c @@ -1,8 +1,12 @@ #include #include #include +#include #include "FLAC/stream_decoder.h" +static int ifd = -1; +static int sts; + static FLAC__StreamDecoderReadStatus decinput(FLAC__StreamDecoder *dec, FLAC__byte buffer[], unsigned *bytes, void *client_data) { @@ -23,7 +27,7 @@ decoutput(FLAC__StreamDecoder *dec, FLAC__Frame *frame, FLAC__int32 *buffer[], v { static int rate, chans, bits; static unsigned char *buf; - static int nbuf, ifd = -1; + static int nbuf; FLAC__int32 *s, v; unsigned char *p; int i, j, n, b, len; @@ -40,8 +44,10 @@ decoutput(FLAC__StreamDecoder *dec, FLAC__Frame *frame, FLAC__int32 *buffer[], v bits = frame->header.bits_per_sample; sprintf(fmt, "s%dr%dc%d", bits, rate, chans); - if(ifd >= 0) + if(ifd >= 0){ close(ifd); + wait(&sts); + } if(pipe(pfd) < 0){ fprintf(stderr, "Error creating pipe\n"); exit(1); @@ -123,5 +129,11 @@ int main(int argc, char *argv[]) FLAC__stream_decoder_init(dec); FLAC__stream_decoder_process_until_end_of_stream(dec); FLAC__stream_decoder_finish(dec); + + if(ifd >= 0){ + close(ifd); + wait(&sts); + } + return 0; }