lkml.org 
[lkml]   [2020]   [May]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH][next] modpost: close file when fstat fails
Date
From: Colin Ian King <colin.king@canonical.com>

Currently a failed fstat error return path fails to close an open file.
Fix this by setting buf to NULL and returning via the error exit path.

Addresses-Coverity: ("Resource leak");
Fixes: commit 076ad831dfe8 ("modpost: add read_text_file() and get_line() helpers")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
scripts/mod/modpost.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index e4691127f051..3012e5f8ec7e 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -109,8 +109,10 @@ char *read_text_file(const char *filename)
if (fd < 0)
return NULL;

- if (fstat(fd, &st) < 0)
- return NULL;
+ if (fstat(fd, &st) < 0) {
+ buf = NULL;
+ goto close;
+ }

buf = NOFAIL(malloc(st.st_size + 1));

--
2.25.1
\
 
 \ /
  Last update: 2020-05-28 17:56    [W:0.025 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site