From 1308f5efe56f05c12cde5b1f2c000f775b0bc8f5 Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Sun, 13 Feb 2022 10:49:23 +0100 Subject: [PATCH] Check for NULL before dereferencing the pointer In case of an error the whole frame is freed, break out of the loop to return early. --- w3mimg/fb/fb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/w3mimg/fb/fb.c b/w3mimg/fb/fb.c index 7960584..8abc1af 100644 --- a/w3mimg/fb/fb.c +++ b/w3mimg/fb/fb.c @@ -426,11 +426,13 @@ fb_frame_new(int w, int h, int n) for (i = 0; i < n; i++) { frame[i] = fb_image_new(w, h); + if (frame[i] == NULL) { + error = 1; + break; + } frame[i]->num = n; frame[i]->id = i; frame[i]->delay = 1000; - if (frame[i] == NULL) - error = 1; } if (error) {