From ae568ce7c4984343f4cd0d2b04457fa596b50f6f Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Wed, 29 Nov 2017 21:30:22 +0100 Subject: [PATCH] ImgIoUtilReadFile: fix file leak upon error the file was not closed in case of malloc error. Change-Id: I5f8b22d7d0da6d2c8c2dd245cdd57994e3ddea3a --- imageio/imageio_util.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/imageio/imageio_util.c b/imageio/imageio_util.c index 10250093..4cb06f2f 100644 --- a/imageio/imageio_util.c +++ b/imageio/imageio_util.c @@ -88,7 +88,12 @@ int ImgIoUtilReadFile(const char* const file_name, file_size = ftell(in); fseek(in, 0, SEEK_SET); file_data = malloc(file_size); - if (file_data == NULL) return 0; + if (file_data == NULL) { + fclose(in); + fprintf(stderr, "memory allocation failure when reading file %s\n", + file_name); + return 0; + } ok = (fread(file_data, file_size, 1, in) == 1); fclose(in);