Skip to content

Commit 6768834

Browse files
committed
Add check for dig here
1 parent 21f1d49 commit 6768834

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

examples/pcr/extend.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ int TPM2_PCR_Extend_Test(void* userCtx, int argc, char *argv[])
7474
BYTE dataBuffer[1024];
7575
enum wc_HashType hashType;
7676
wc_HashAlg dig;
77+
int hashInitialized = 0;
7778
#endif
7879

7980
union {
@@ -154,6 +155,8 @@ int TPM2_PCR_Extend_Test(void* userCtx, int argc, char *argv[])
154155
rc = TPM2_GetHashType(alg);
155156
hashType = (enum wc_HashType)rc;
156157
rc = wc_HashInit(&dig, hashType);
158+
if (rc == 0)
159+
hashInitialized = 1;
157160
while (rc == 0 && !XFEOF(fp)) {
158161
len = XFREAD(dataBuffer, 1, sizeof(dataBuffer), fp);
159162
if (len > 0) {
@@ -163,7 +166,8 @@ int TPM2_PCR_Extend_Test(void* userCtx, int argc, char *argv[])
163166
XFCLOSE(fp);
164167
if (rc == 0)
165168
rc = wc_HashFinal(&dig, hashType, hash);
166-
wc_HashFree(&dig, hashType);
169+
if (hashInitialized)
170+
wc_HashFree(&dig, hashType);
167171
if (rc != 0) {
168172
printf("Hash operation failed %d\n", rc);
169173
goto exit;

0 commit comments

Comments
 (0)