diff mbox series

[ndctl,2/2] ndctl/namespace: fix a resource leak in file_write_infoblock()

Message ID 20200722052655.21296-3-vishal.l.verma@intel.com (mailing list archive)
State Accepted
Commit 560a1bf273ede58886a9aab02aa077deddc13daa
Headers show
Series misc fixes and cleanup | expand

Commit Message

Verma, Vishal L July 22, 2020, 5:26 a.m. UTC
Static analysis showed that we might leak 'fd' in the given function.
Fix the error path to close(fd) if 'fd >= 0' rather than just 'fd > 0'.

Fixes: 7787807bcffe ("ndctl/namespace: Add write-infoblock command")
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/namespace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 8aa5a42..e734248 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -1969,7 +1969,7 @@  static int file_write_infoblock(const char *path)
 
 	free(buf);
 out:
-	if (fd > 0 && fd != STDOUT_FILENO)
+	if (fd >= 0 && fd != STDOUT_FILENO)
 		close(fd);
 	return rc;
 }