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 <[email protected]>
Signed-off-by: Vishal Verma <[email protected]>
---
ndctl/namespace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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;
}
--
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]