Merge pull request #7093 from Lawrence37/fix-unclosed-jpg-file
Always close JPEG after reading
This commit is contained in:
@@ -485,7 +485,11 @@ int ImageIO::loadJPEGFromMemory (const char* buffer, int bufsize)
|
|||||||
|
|
||||||
int ImageIO::loadJPEG (const Glib::ustring &fname)
|
int ImageIO::loadJPEG (const Glib::ustring &fname)
|
||||||
{
|
{
|
||||||
FILE *file = g_fopen(fname.c_str (), "rb");
|
std::unique_ptr<FILE, void (*)(FILE *)> file(
|
||||||
|
g_fopen(fname.c_str(), "rb"),
|
||||||
|
[](FILE *f) {
|
||||||
|
fclose(f);
|
||||||
|
});
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return IMIO_CANNOTREADFILE;
|
return IMIO_CANNOTREADFILE;
|
||||||
@@ -496,7 +500,7 @@ int ImageIO::loadJPEG (const Glib::ustring &fname)
|
|||||||
cinfo.err = my_jpeg_std_error(&jerr);
|
cinfo.err = my_jpeg_std_error(&jerr);
|
||||||
jpeg_create_decompress(&cinfo);
|
jpeg_create_decompress(&cinfo);
|
||||||
|
|
||||||
my_jpeg_stdio_src (&cinfo, file);
|
my_jpeg_stdio_src (&cinfo, file.get());
|
||||||
|
|
||||||
#if defined( _WIN32 ) && defined( __x86_64__ ) && !defined(__clang__)
|
#if defined( _WIN32 ) && defined( __x86_64__ ) && !defined(__clang__)
|
||||||
if ( __builtin_setjmp((reinterpret_cast<rt_jpeg_error_mgr*>(cinfo.src))->error_jmp_buf) == 0 ) {
|
if ( __builtin_setjmp((reinterpret_cast<rt_jpeg_error_mgr*>(cinfo.src))->error_jmp_buf) == 0 ) {
|
||||||
@@ -558,7 +562,7 @@ int ImageIO::loadJPEG (const Glib::ustring &fname)
|
|||||||
|
|
||||||
jpeg_finish_decompress(&cinfo);
|
jpeg_finish_decompress(&cinfo);
|
||||||
jpeg_destroy_decompress(&cinfo);
|
jpeg_destroy_decompress(&cinfo);
|
||||||
fclose(file);
|
file.reset();
|
||||||
|
|
||||||
if (pl) {
|
if (pl) {
|
||||||
pl->setProgressStr ("PROGRESSBAR_READY");
|
pl->setProgressStr ("PROGRESSBAR_READY");
|
||||||
|
Reference in New Issue
Block a user