From 453d3db8a5997396608de15a70263470f55ae093 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 13 Aug 2015 18:21:53 +0200 Subject: [PATCH] tpm_pcr_read: close file when returning early When return from inside the for() loop, the open file was not closed. Signed-off-by: Patrick Ohly --- src/evmctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/evmctl.c b/src/evmctl.c index c20cbfe..64d721f 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -1143,6 +1143,7 @@ static int tpm_pcr_read(int idx, uint8_t *pcr, int len) { FILE *fp; char *p, pcr_str[7], buf[70]; /* length of the TPM string */ + int result = -1; sprintf(pcr_str, "PCR-%d", idx); @@ -1158,11 +1159,12 @@ static int tpm_pcr_read(int idx, uint8_t *pcr, int len) break; if (!strncmp(p, pcr_str, 6)) { hex2bin(pcr, p + 7, len); - return 0; + result = 0; + break; } } fclose(fp); - return -1; + return result; } #define TCG_EVENT_NAME_LEN_MAX 255