Fix memleak in CapturePix (#1762)

This commit is contained in:
Vladimir Olteanu 2021-04-30 09:02:02 +03:00 committed by GitHub
commit af50ed7302
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -116,16 +116,15 @@ static BYTE *CaptureEnc(BYTE *src, BYTE *dst, int width)
static bool CapturePix(const CelOutputBuffer &buf, std::ofstream *out)
{
int width = buf.w();
BYTE *pBuffer = (BYTE *)DiabloAllocPtr(2 * width);
auto pBuffer = std::make_unique<BYTE[]>(2 * width);
BYTE *pixels = buf.begin();
for (int height = buf.h(); height > 0; height--) {
const BYTE *pBufferEnd = CaptureEnc(pixels, pBuffer, width);
const BYTE *pBufferEnd = CaptureEnc(pixels, pBuffer.get(), width);
pixels += buf.pitch();
out->write(reinterpret_cast<const char *>(pBuffer), pBufferEnd - pBuffer);
out->write(reinterpret_cast<const char *>(pBuffer.get()), pBufferEnd - pBuffer.get());
if (out->fail())
return false;
}
mem_free_dbg(pBuffer);
return true;
}