mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 14:08:19 +00:00
Fix double-free when reading opus file fails
Set the data pointer of the sample only when the sample has been loaded successfully, so the invalid sample data is not freed again when decoding fails.
This commit is contained in:
parent
941a302c4d
commit
1153507216
|
@ -355,15 +355,15 @@ bool CSound::DecodeOpus(CSample &Sample, const void *pData, unsigned DataSize) c
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sample.m_pData = (short *)calloc((size_t)NumSamples * NumChannels, sizeof(short));
|
short *pSampleData = (short *)calloc((size_t)NumSamples * NumChannels, sizeof(short));
|
||||||
|
|
||||||
int Pos = 0;
|
int Pos = 0;
|
||||||
while(Pos < NumSamples)
|
while(Pos < NumSamples)
|
||||||
{
|
{
|
||||||
const int Read = op_read(pOpusFile, Sample.m_pData + Pos * NumChannels, NumSamples * NumChannels, nullptr);
|
const int Read = op_read(pOpusFile, pSampleData + Pos * NumChannels, NumSamples * NumChannels, nullptr);
|
||||||
if(Read < 0)
|
if(Read < 0)
|
||||||
{
|
{
|
||||||
free(Sample.m_pData);
|
free(pSampleData);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -372,6 +372,7 @@ bool CSound::DecodeOpus(CSample &Sample, const void *pData, unsigned DataSize) c
|
||||||
Pos += Read;
|
Pos += Read;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Sample.m_pData = pSampleData;
|
||||||
Sample.m_NumFrames = Pos;
|
Sample.m_NumFrames = Pos;
|
||||||
Sample.m_Rate = 48000;
|
Sample.m_Rate = 48000;
|
||||||
Sample.m_LoopStart = -1;
|
Sample.m_LoopStart = -1;
|
||||||
|
|
Loading…
Reference in a new issue