xtest: sdp: fix resource leak in get_random_bytes()
Close file descriptor before returning when failing to read
from /dev/urandom.
Fixes: 41343db4 ("xtest: add SDP basic tests")
Signed-off-by: Cyrille Fleury <cyrille.fleury@nxp.com>
Reviewed-by: Jerome Forissier <jerome@forissier.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
diff --git a/host/xtest/sdp_basic.c b/host/xtest/sdp_basic.c
index 5749714..8da6a88 100644
--- a/host/xtest/sdp_basic.c
+++ b/host/xtest/sdp_basic.c
@@ -402,6 +402,7 @@
if (rc != RANDOM_BUFFER_SIZE) {
fprintf(stderr, "failed to read %d bytes from %s\n",
RANDOM_BUFFER_SIZE, rand_dev);
+ close(fd);
return -1;
}
close(fd);