1
0
Fork 0

Prevent resource leak during screenshot

Using RAII would be a better solution, but it requires non-trivial
code refactor in this area.
This commit is contained in:
Patryk Obara 2020-01-05 21:15:02 +01:00 committed by Patryk Obara
parent 0d71bf0ea4
commit f3f33c5ea1

View file

@ -321,14 +321,19 @@ void CAPTURE_AddImage(Bitu width, Bitu height, Bitu bpp, Bitu pitch, Bitu flags,
CaptureState &= ~CAPTURE_IMAGE;
/* Open the actual file */
FILE * fp=OpenCaptureFile("Screenshot",".png");
if (!fp) goto skip_shot;
FILE *fp = OpenCaptureFile("Screenshot", ".png");
if (!fp)
goto skip_shot;
/* First try to allocate the png structures */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,NULL, NULL);
if (!png_ptr) goto skip_shot;
if (!png_ptr) {
fclose(fp);
goto skip_shot;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr,(png_infopp)NULL);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
fclose(fp);
goto skip_shot;
}