Fix memory leaks around PNG/sprite handling (#10711)

This commit is contained in:
Michał Janiszewski 2020-02-16 07:25:30 +01:00 committed by GitHub
parent 50567d31ce
commit 38907fd0c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -222,7 +222,8 @@ static bool sprite_file_export(int32_t spriteIndex, const char* outPath)
spriteHeader = &spriteFileEntries[spriteIndex];
pixelBufferSize = spriteHeader->width * spriteHeader->height;
pixels = (uint8_t*)malloc(pixelBufferSize);
std::unique_ptr<uint8_t[]> pixelBuffer(new uint8_t[pixelBufferSize]);
pixels = pixelBuffer.get();
std::fill_n(pixels, pixelBufferSize, 0x00);
dpi.bits = pixels;

View File

@ -232,6 +232,7 @@ namespace Imaging
}
png_write_end(png_ptr, nullptr);
png_destroy_info_struct(png_ptr, &info_ptr);
png_free(png_ptr, png_palette);
png_destroy_write_struct(&png_ptr, nullptr);
}