From: Andreas Reichel <
andreas.r...@siemens.com>
* Test for fd < 0 instead of fd == 0
* close fd before return to prevent handle leak
Signed-off-by: Andreas Reichel <
andreas.r...@siemens.com>
---
tools/ebgpart.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/ebgpart.c b/tools/ebgpart.c
index f80bdfe..ef99ace 100644
--- a/tools/ebgpart.c
+++ b/tools/ebgpart.c
@@ -255,7 +255,7 @@ static bool check_partition_table(PedDevice *dev)
VERBOSE(stdout, "Checking %s\n", dev->path);
fd = open(dev->path, O_RDONLY);
- if (fd == 0) {
+ if (fd < 0) {
VERBOSE(stderr, "Error opening block device.\n");
return false;
}
@@ -294,6 +294,7 @@ static bool check_partition_table(PedDevice *dev)
struct EFIHeader efihdr;
if (read(fd, &efihdr, sizeof(efihdr)) !=
sizeof(efihdr)) {
+ close(fd);
VERBOSE(stderr, "Error reading EFI Header\n.");
VERBOSE(stderr, "(%s)", strerror(errno));
return false;
--
2.14.2