From 91ba796c0f15dfc1a8e11f58ecbfe5a86b706f80 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 14 Oct 2019 14:14:16 +0900 Subject: [PATCH] vector stb: free the memory properly in the exception cases. Change-Id: Ib2699f068217f20f565a2045f7e0fc53f32a8f95 --- src/vector/stb/stb_image.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/vector/stb/stb_image.h b/src/vector/stb/stb_image.h index aa58412..8c039ef 100644 --- a/src/vector/stb/stb_image.h +++ b/src/vector/stb/stb_image.h @@ -1178,8 +1178,10 @@ STBIDEF stbi_uc *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req result = stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp); if (result) { // need to 'unget' all the characters in the IO buffer - if (fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR) == -1) + if (fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR) == -1) { + stbi_image_free(result); return stbi__errpuc("fseek() error", "File Seek Fail"); + } } return result; } @@ -1192,8 +1194,10 @@ STBIDEF stbi__uint16 *stbi_load_from_file_16(FILE *f, int *x, int *y, int *comp, result = stbi__load_and_postprocess_16bit(&s,x,y,comp,req_comp); if (result) { // need to 'unget' all the characters in the IO buffer - if (fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR) == -1) + if (fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR) == -1) { + stbi_image_free(result); return (stbi__uint16 *) stbi__errpuc("fseek() error", "File Seek Fail"); + } } return result; } -- 2.7.4