swtpm_cert: Free variable before parsing it to avoid memory leak (Coverity)
Avoid memory leaks if one of the parameters --tcp, --tpm-device,
or --unix was passed multiple times by freeing the previously
parsed value.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
diff --git a/src/swtpm_bios/tpm_bios.c b/src/swtpm_bios/tpm_bios.c
index a1f1b81..c90f9e1 100644
--- a/src/swtpm_bios/tpm_bios.c
+++ b/src/swtpm_bios/tpm_bios.c
@@ -712,6 +712,7 @@
#endif
switch (opt) {
case 'D':
+ free(tpm_device);
tpm_device = strdup(optarg);
if (!tpm_device) {
fprintf(stderr, "Out of memory.");
@@ -719,11 +720,13 @@
}
break;
case 'T':
+ free(tcp_hostname);
if (parse_tcp_optarg(optarg, &tcp_hostname, &tcp_port) < 0) {
return EXIT_FAILURE;
}
break;
case 'U':
+ free(unix_path);
unix_path = strdup(optarg);
if (!unix_path) {
fprintf(stderr, "Out of memory.\n");