ndctl/0001-ndctl-namespace-fix-a-resource-leak-in-file_write_in.patch

33 lines
970 B
Diff
Raw Normal View History

From b0d9cad81f2e811608b898922643f655043361aa Mon Sep 17 00:00:00 2001
From: Vishal Verma <vishal.l.verma@intel.com>
Date: Tue, 21 Jul 2020 23:17:27 -0600
Subject: [PATCH 1/2] ndctl/namespace: fix a resource leak in
file_write_infoblock()
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 --git a/ndctl/namespace.c b/ndctl/namespace.c
index 0550580..17e67c9 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -1977,7 +1977,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;
}
--
1.8.3.1