From b1c98acf33c962c7c05be1152fa1ae4bd5daaeb5 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 19 Jun 2014 17:50:03 -0700 Subject: [PATCH] Close the file handle in the sndfile decoder --- src/sound/audio_sndfile_decoder.cpp | 16 ++++++++++------ src/sound/i_soundinternal.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/sound/audio_sndfile_decoder.cpp b/src/sound/audio_sndfile_decoder.cpp index dfb49b08c..b71a41721 100644 --- a/src/sound/audio_sndfile_decoder.cpp +++ b/src/sound/audio_sndfile_decoder.cpp @@ -145,6 +145,9 @@ SndFileDecoder::~SndFileDecoder() if(SndFile) sf_close(SndFile); SndFile = 0; + if(File) + fclose(File); + File = 0; } bool SndFileDecoder::open(const char *data, size_t length) @@ -157,14 +160,14 @@ bool SndFileDecoder::open(const char *data, size_t length) SndFile = sf_open_virtual(&sfio, SFM_READ, &SndInfo, this); if(SndFile) { - if(SndInfo.channels != 1 && SndInfo.channels != 2) - { - sf_close(SndFile); - SndFile = 0; - } + if(SndInfo.channels == 1 || SndInfo.channels == 2) + return true; + + sf_close(SndFile); + SndFile = 0; } - return SndFile != 0; + return false; } bool SndFileDecoder::open(const char *fname, size_t offset, size_t length) @@ -189,6 +192,7 @@ bool SndFileDecoder::open(const char *fname, size_t offset, size_t length) } } fclose(File); + File = 0; } return false; diff --git a/src/sound/i_soundinternal.h b/src/sound/i_soundinternal.h index 4351fe0fe..2b3544521 100644 --- a/src/sound/i_soundinternal.h +++ b/src/sound/i_soundinternal.h @@ -182,7 +182,7 @@ struct SndFileDecoder : public SoundDecoder virtual bool seek(size_t ms_offset); virtual size_t getSampleOffset(); - SndFileDecoder() : SndFile(0) { } + SndFileDecoder() : SndFile(0), File(0) { } virtual ~SndFileDecoder(); protected: