objtool: fix resource leak in copy_file()
PATCH 1/1 objtool: fix resource leak in copy_file()
Close open file descriptors on error paths in copy_file() to prevent resource leaks when open(), fstat(), fchmod(), or sendfile() fail.
Fixes 5a406031d071 ("objtool: Add --output option")
Signed-off-by Qasim Ijaz <[email protected]>
--- tools/objtool/builtin-check.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/objtool/builtin-check.c +7 -0
@@ -201,16 +201,21 @@ static int copy_file(const char *src, const char *dst) dst_fd =open (dst,O_WRONLY |O_CREAT |O_TRUNC ,0400 );if (dst_fd ==-1 ) {ERROR ("can't open '%s' for writing" , dst); +close (src_fd);return 1 ; }if (fstat (src_fd, &stat) ==-1 ) {perror ("fstat" ); +close (src_fd); +close (dst_fd);return 1 ; }if (fchmod (dst_fd, stat.st_mode) ==-1 ) {perror ("fchmod" ); +close (src_fd); +close (dst_fd);return 1 ; }
@@ -218,6 +223,8 @@ static int copy_file(const char *src, const char *dst) copied =sendfile (dst_fd, src_fd, &offset, to_copy);if (copied ==-1 ) {perror ("sendfile" ); +close (src_fd); +close (dst_fd);return 1 ; } }
Signature · 1 line
2.39.5
Josh Poimboeuf
maintainerQuoted 5 lines · Qasim Ijaz
Close open file descriptors on error paths in
copy_file()to prevent resource leaks whenopen(),fstat(),fchmod(), orsendfile()fail.Fixes 5a406031d071 ("objtool: Add --output option")Signed-off-by Qasim Ijaz <[email protected]>
Hi,
Thanks for the patch, but objtool is a short running process, so we generally don't care about memory leaks.
Signature · 1 line
Josh