diff mbox series

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

Message ID 20240605134054.2626953-28-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit 657d9516064bc1933768f24fa72c2471d15a2b39
Headers show
Series trace-cmd: fix misc issues found by static analysis | expand

Commit Message

Jerome Marchand June 5, 2024, 1:40 p.m. UTC
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 <jmarchan@redhat.com>
---
 lib/trace-cmd/trace-output.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

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");