[PATCH 27/38] trace-cmd lib: prevent a possible file descriptor leak in set_proc_kptr_restrict()

"Jerome Marchand" <[email protected]>
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
In set_proc_kptr_restrict() we test whether fd > 0 to close it.
Theorically, open() could have returned zero if stdin was closed. I
don't think it could happen here, but changing the test with fd >= 0
silence the static analyser which complains about a ressource leak.

Signed-off-by: Jerome Marchand <[email protected]>
---
 lib/trace-cmd/trace-output.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index 7be175af..6a9606c7 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -1124,7 +1124,7 @@ static void set_proc_kptr_restrict(int reset)
 	if (write(fd, &buf, 1) > 0)
 		ret = 0;
 err:
-	if (fd > 0)
+	if (fd >= 0)
 		close(fd);
 	if (ret)
 		tracecmd_warning("can't set kptr_restrict");
-- 
2.44.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.