From f51ceeee21ab4e3754490e931ead603d0fa22440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Mon, 5 Jun 2023 10:56:48 +0200 Subject: [PATCH] lib/bitmap: Fix a potential memory leak (#3004) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit map is initinialized but not free'd Co-authored-by: Loïc Bartoletti --- lib/bitmap/bitmap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/bitmap/bitmap.c b/lib/bitmap/bitmap.c index 991cf9dfac0..bb64d9b13ec 100644 --- a/lib/bitmap/bitmap.c +++ b/lib/bitmap/bitmap.c @@ -315,8 +315,11 @@ struct BM *BM_file_read(FILE *fp) if (NULL == (map = (struct BM *)malloc(sizeof(struct BM)))) return (NULL); - if (fread(&c, sizeof(char), sizeof(char), fp) != sizeof(char)) + if (fread(&c, sizeof(char), sizeof(char), fp) != sizeof(char)) { + free(map); return NULL; + } + if (c != BM_MAGIC) { free(map); return NULL;