From c54bb11ee9caeffe716b3f7d240f76afe991e965 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 31 May 2014 19:58:43 +0200 Subject: [PATCH] WPrefs: fix memory leak in loadRImage (Coverity #50107) As pointed by Coverity, if there is a problem when reading the binary data of an RImage from a file, the area allocated to store it would not be freed. Signed-off-by: Christophe CURIS --- WPrefs.app/Appearance.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/WPrefs.app/Appearance.c b/WPrefs.app/Appearance.c index f67975d9..05354952 100644 --- a/WPrefs.app/Appearance.c +++ b/WPrefs.app/Appearance.c @@ -1276,13 +1276,13 @@ static Pixmap loadRImage(WMScreen * scr, const char *path) } image = RCreateImage(w, h, d == 4); read_size = w * h * d; - if (fread(image->data, 1, read_size, f) != read_size) { - fclose(f); - return None; - } + if (fread(image->data, 1, read_size, f) == read_size) + RConvertImage(WMScreenRContext(scr), image, &pixmap); + else + pixmap = None; + fclose(f); - RConvertImage(WMScreenRContext(scr), image, &pixmap); RReleaseImage(image); return pixmap;