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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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





[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux