Skip to content

Commit 5a5a7e2

Browse files
committed
Fix issue with possible handle leak in bench example. Reported in #411.
1 parent 122885a commit 5a5a7e2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

examples/bench/bench.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ static int bench_sym_hash(WOLFTPM2_DEV* dev, const char* desc, int algo,
147147
bench_stats_sym_finish(desc, count, inSz, start);
148148

149149
exit:
150+
wolfTPM2_UnloadHandle(dev, &hash.handle);
150151
return rc;
151152
}
152153

@@ -185,7 +186,6 @@ static int bench_sym_aes(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* storageKey,
185186
bench_stats_sym_finish(desc, count, inOutSz, start);
186187

187188
exit:
188-
189189
wolfTPM2_UnloadHandle(dev, &aesKey.handle);
190190
return rc;
191191
}
@@ -489,14 +489,15 @@ int TPM2_Wrapper_BenchArgs(void* userCtx, int argc, char *argv[])
489489
if (rc != 0) goto exit;
490490

491491
exit:
492-
493492
if (rc != 0) {
494493
printf("Failure 0x%x: %s\n", rc, wolfTPM2_GetRCString(rc));
495494
}
496495

496+
/* Cleanup all handles */
497497
wolfTPM2_UnloadHandle(&dev, &rsaKey.handle);
498498
wolfTPM2_UnloadHandle(&dev, &eccKey.handle);
499499
wolfTPM2_UnloadHandle(&dev, &tpmSession.handle);
500+
wolfTPM2_UnloadHandle(&dev, &storageKey.handle);
500501

501502
wolfTPM2_Cleanup(&dev);
502503

0 commit comments

Comments
 (0)