Fix memory leak of opus file structure

We were not calling `op_free` for `OggOpusFile *` after decoding opus files.
This commit is contained in:
Robert Müller 2024-04-25 20:28:07 +02:00
parent cfb5b15222
commit d0e27fdcd4

View file

@ -350,6 +350,7 @@ bool CSound::DecodeOpus(CSample &Sample, const void *pData, unsigned DataSize) c
if(NumChannels > 2) if(NumChannels > 2)
{ {
op_free(pOpusFile);
dbg_msg("sound/opus", "file is not mono or stereo."); dbg_msg("sound/opus", "file is not mono or stereo.");
return false; return false;
} }
@ -363,6 +364,7 @@ bool CSound::DecodeOpus(CSample &Sample, const void *pData, unsigned DataSize) c
if(Read < 0) if(Read < 0)
{ {
free(pSampleData); free(pSampleData);
op_free(pOpusFile);
dbg_msg("sound/opus", "op_read error %d at %d", Read, Pos); dbg_msg("sound/opus", "op_read error %d at %d", Read, Pos);
return false; return false;
} }
@ -371,6 +373,8 @@ bool CSound::DecodeOpus(CSample &Sample, const void *pData, unsigned DataSize) c
Pos += Read; Pos += Read;
} }
op_free(pOpusFile);
Sample.m_pData = pSampleData; Sample.m_pData = pSampleData;
Sample.m_NumFrames = Pos; Sample.m_NumFrames = Pos;
Sample.m_Rate = 48000; Sample.m_Rate = 48000;