mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
RTech: move ZStd free code to actual decoder
Let the decoder free it to avoid memory leaks
This commit is contained in:
parent
b81beecdf1
commit
86f9dbe30f
@ -502,11 +502,10 @@ PakRingBufferFrame_t Pak_ComputeRingBufferFrame(const uint64_t bufMask, const ui
|
||||
|
||||
bool Pak_ZStreamDecode(PakDecoder_t* const decoder, const size_t inLen, const size_t outLen)
|
||||
{
|
||||
// must have a zstream decoder at this point
|
||||
assert(decoder->zstreamContext);
|
||||
|
||||
if (decoder->inBufBytePos >= inLen)
|
||||
return false;
|
||||
// must have a zstream decoder at this point, and input seek pos may not
|
||||
// exceed or equal inLen as we can't read past currently streamed data;
|
||||
// this should've been checked before calling this function
|
||||
assert(decoder->zstreamContext && decoder->inBufBytePos < inLen);
|
||||
|
||||
PakRingBufferFrame_t outFrame = Pak_ComputeRingBufferFrame(decoder->outputMask, decoder->outBufBytePos, outLen);
|
||||
|
||||
@ -543,7 +542,16 @@ bool Pak_ZStreamDecode(PakDecoder_t* const decoder, const size_t inLen, const si
|
||||
decoder->inBufBytePos += inBuffer.pos;
|
||||
decoder->outBufBytePos += outBuffer.pos;
|
||||
|
||||
return ret == NULL;
|
||||
const bool decoded = ret == NULL;
|
||||
|
||||
// zstd decoder no longer necessary at this point, deallocate
|
||||
if (decoded)
|
||||
{
|
||||
ZSTD_freeDStream(decoder->zstreamContext);
|
||||
decoder->zstreamContext = nullptr;
|
||||
}
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -415,15 +415,6 @@ LABEL_18:
|
||||
|
||||
if (didDecode)
|
||||
DevMsg(eDLL_T::RTECH, "%s: pak '%s' decoded successfully\n", __FUNCTION__, pak->GetName());
|
||||
|
||||
if (didDecode)
|
||||
{
|
||||
if (useZStream && decodeContext->zstreamContext)
|
||||
{
|
||||
ZSTD_freeDStream(decodeContext->zstreamContext);
|
||||
decodeContext->zstreamContext = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compressedSize = v22->compressedSize;
|
||||
|
Loading…
x
Reference in New Issue
Block a user