From fbbb56b52b4ee36c9492ef896cb670c013056256 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Wed, 16 Feb 2022 10:35:14 -0500 Subject: [PATCH] swtpm_setup: Free string array in case of failure Free the allocated string array in case of failure. Existing callers auto-free the array already, so there's no memory leak, but it is better to free it in the function where it is allocated. Signed-off-by: Stefan Berger --- src/swtpm_setup/swtpm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/swtpm_setup/swtpm.c b/src/swtpm_setup/swtpm.c index 00a90ba..17689a9 100644 --- a/src/swtpm_setup/swtpm.c +++ b/src/swtpm_setup/swtpm.c @@ -506,6 +506,8 @@ static int swtpm_tpm2_get_all_pcr_banks(struct swtpm *self, gchar ***all_pcr_ban if (ret != 0) return 1; + *all_pcr_banks = NULL; + if (tpmresp_len < 17 + sizeof(count)) goto err_too_short; memcpy(&count, &tpmresp[17], sizeof(count)); @@ -541,6 +543,10 @@ static int swtpm_tpm2_get_all_pcr_banks(struct swtpm *self, gchar ***all_pcr_ban err_too_short: logerr(self->logfile, "Response from TPM2_GetCapability is too short!\n"); + + g_strfreev(*all_pcr_banks); + *all_pcr_banks = NULL; + return 1; }