From 73918bc788241b1eb819716af6595f8b32e9e701 Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Mon, 12 Aug 2024 12:52:36 -0500 Subject: [PATCH] cpukit/libblock: Close all valid FDs This is intended to close any valid FDs that were opened, but 0 is also a valid FD. This change ensures that a FD of 0 is also closed properly. Coverity CID 1467408 (original) Coverity CID 1616151 (followup) off_by_one: Testing whether handle fd is strictly greater than zero is suspicious. fd leaks when it is zero. --- cpukit/libblock/src/bdpart-register.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpukit/libblock/src/bdpart-register.c b/cpukit/libblock/src/bdpart-register.c index 68f602ac12..b3b1736045 100644 --- a/cpukit/libblock/src/bdpart-register.c +++ b/cpukit/libblock/src/bdpart-register.c @@ -213,7 +213,7 @@ cleanup: * but fd may be -1. Coverity flagged passing a bad value to close(). */ free( logical_disk_name); - if (fd > 0) { + if (fd >= 0) { close( fd); }