ref: bc97fa79b1b1d5e731f949d92d35d7ad839f1d35
parent: 523c33bb6f61260c14ec12ea25b0bba89ba4e856
author: cinap_lenrek <[email protected]>
date: Mon Dec 15 02:26:03 EST 2014
audio/flacdec: fix pcmconv pipeline race (thanks mischief and henesy)
--- a/sys/src/cmd/audio/flacdec/flacdec.c
+++ b/sys/src/cmd/audio/flacdec/flacdec.c
@@ -1,8 +1,12 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
+#include <sys/wait.h>
#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 @@
{
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 @@
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 @@
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;
}