[Ocfs2-tools-devel] [PATCH 4/5] libo2dlm: Close file description after use

piaojun piaojun at huawei.com
Thu Apr 2 05:46:47 PDT 2015


In o2dlm_generate_random_value(), randfd should be closed after use.

Signed-off-by: Jun Piao <piaojun at huawei.com>
Reviewed-by: Alex Chen <alex.chen at huawei.com>

---
 libo2dlm/o2dlm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libo2dlm/o2dlm.c b/libo2dlm/o2dlm.c
index dbc642b..375f659 100644
--- a/libo2dlm/o2dlm.c
+++ b/libo2dlm/o2dlm.c
@@ -102,9 +102,10 @@ static errcode_t o2dlm_generate_random_value(int64_t *value)
 	if ((randfd = open("/dev/urandom", O_RDONLY)) == -1)
 		return O2DLM_ET_RANDOM;

-	if (read(randfd, value, readlen) != readlen)
+	if (read(randfd, value, readlen) != readlen) {
+		close(randfd);
 		return O2DLM_ET_RANDOM;
-
+	}
 	close(randfd);

 	return 0;
-- 
1.8.4.3




More information about the Ocfs2-tools-devel mailing list