aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-06-28 12:51:26 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-06-28 12:51:26 +0000
commit178e6c52635fa0f2c76095ab57de89b908028ff9 (patch)
tree24aa4bc8426b005acd34889425fe3f9327758641
parent366e370cb0d5f623b5b46c8419c895408b2fb756 (diff)
downloadmpd-178e6c52635fa0f2c76095ab57de89b908028ff9.tar.gz
mpd-178e6c52635fa0f2c76095ab57de89b908028ff9.tar.xz
mpd-178e6c52635fa0f2c76095ab57de89b908028ff9.zip
fix some memory leaks in flac_plugin - from normalperson
git-svn-id: https://svn.musicpd.org/mpd/trunk@1699 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/inputPlugins/flac_plugin.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c
index 8ae631a97..492d5a80a 100644
--- a/src/inputPlugins/flac_plugin.c
+++ b/src/inputPlugins/flac_plugin.c
@@ -70,9 +70,11 @@ FLAC__SeekableStreamDecoderLengthStatus flacLength(
FLAC__bool flacEOF(const FLAC__SeekableStreamDecoder *, void *);
int flac_decode(OutputBuffer * cb, DecoderControl *dc, char * path) {
- FLAC__SeekableStreamDecoder * flacDec;
+ FLAC__SeekableStreamDecoder * flacDec = NULL;
FlacData data;
int status = 1;
+ int ret =0;
+ int streamOpen = 0;
data.chunk_length = 0;
data.time = 0;
@@ -85,10 +87,15 @@ int flac_decode(OutputBuffer * cb, DecoderControl *dc, char * path) {
if(openInputStream(&(data.inStream), path)<0) {
ERROR("unable to open flac: %s\n", path);
- return -1;
+ ret = -1;
+ goto fail;
}
+ streamOpen = 1;
- if(!(flacDec = FLAC__seekable_stream_decoder_new())) return -1;
+ if(!(flacDec = FLAC__seekable_stream_decoder_new())) {
+ ret = -1;
+ goto fail;
+ }
/*status&=FLAC__file_decoder_set_md5_checking(flacDec,1);*/
status&=FLAC__seekable_stream_decoder_set_read_callback(flacDec,
flacRead);
@@ -112,8 +119,8 @@ int flac_decode(OutputBuffer * cb, DecoderControl *dc, char * path) {
flacPrintErroredState(
FLAC__seekable_stream_decoder_get_state(flacDec),
path);
- FLAC__seekable_stream_decoder_delete(flacDec);
- return -1;
+ ret = -1;
+ goto fail;
}
if(FLAC__seekable_stream_decoder_init(flacDec)!=
@@ -123,8 +130,8 @@ int flac_decode(OutputBuffer * cb, DecoderControl *dc, char * path) {
flacPrintErroredState(
FLAC__seekable_stream_decoder_get_state(flacDec),
path);
- FLAC__seekable_stream_decoder_delete(flacDec);
- return -1;
+ ret = -1;
+ goto fail;
}
if(!FLAC__seekable_stream_decoder_process_until_end_of_metadata(flacDec)) {
@@ -132,8 +139,8 @@ int flac_decode(OutputBuffer * cb, DecoderControl *dc, char * path) {
flacPrintErroredState(
FLAC__seekable_stream_decoder_get_state(flacDec),
path);
- FLAC__seekable_stream_decoder_delete(flacDec);
- return -1;
+ ret = -1;
+ goto fail;
}
dc->state = DECODE_STATE_DECODE;
@@ -168,7 +175,6 @@ int flac_decode(OutputBuffer * cb, DecoderControl *dc, char * path) {
path);
FLAC__seekable_stream_decoder_finish(flacDec);
}
- FLAC__seekable_stream_decoder_delete(flacDec);
/* send last little bit */
if(data.chunk_length>0 && !dc->stop) {
flacSendChunk(&data);
@@ -186,7 +192,12 @@ int flac_decode(OutputBuffer * cb, DecoderControl *dc, char * path) {
}
else dc->state = DECODE_STATE_STOP;
- return 0;
+fail:
+ if(streamOpen) closeInputStream(&(data.inStream));
+
+ if(flacDec) FLAC__seekable_stream_decoder_delete(flacDec);
+
+ return ret;
}
FLAC__SeekableStreamDecoderReadStatus flacRead(
@@ -576,4 +587,3 @@ InputPlugin flacPlugin =
};
#endif
-/* vim:set shiftwidth=8 tabstop=8 expandtab: */