All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] objtool: fix resource leak in copy_file()
@ 2025-03-20 23:31 Qasim Ijaz
  2025-03-20 23:46 ` Josh Poimboeuf
  0 siblings, 1 reply; 2+ messages in thread
From: Qasim Ijaz @ 2025-03-20 23:31 UTC (permalink / raw)
  To: jpoimboe, peterz; +Cc: linux-kernel

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 <qasdev00@gmail.com>
---
 tools/objtool/builtin-check.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 5f761f420b8c..3357049d840f 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -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;
 		}
 	}
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] objtool: fix resource leak in copy_file()
  2025-03-20 23:31 [PATCH] objtool: fix resource leak in copy_file() Qasim Ijaz
@ 2025-03-20 23:46 ` Josh Poimboeuf
  0 siblings, 0 replies; 2+ messages in thread
From: Josh Poimboeuf @ 2025-03-20 23:46 UTC (permalink / raw)
  To: Qasim Ijaz; +Cc: peterz, linux-kernel

On Thu, Mar 20, 2025 at 11:31:31PM +0000, Qasim Ijaz wrote:
> 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 <qasdev00@gmail.com>

Hi,

Thanks for the patch, but objtool is a short running process, so we
generally don't care about memory leaks.

-- 
Josh

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-03-20 23:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-20 23:31 [PATCH] objtool: fix resource leak in copy_file() Qasim Ijaz
2025-03-20 23:46 ` Josh Poimboeuf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.