modpost: close file when fstat fails
Subsystems (2)
PATCH 1/1 modpost: close file when fstat fails
From: Colin Ian King <[email protected]>
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 <[email protected]>
--- scripts/mod/modpost.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
scripts/mod/modpost.c +4 -2
@@ -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 ));
Signature · 1 line
2.25.1