From 62846ee6a0c79d0098bcd5bece2af5955c4e3646 Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Sun, 9 Nov 2025 11:53:21 +0000 Subject: [PATCH 04/20] tpm2_checkquote: Fix memory leaks, malloced buffer not always freed A buffer allocated with malloc was not freed in all possible paths, not even in the success path. Signed-off-by: Dimitrios Siganos --- tools/misc/tpm2_checkquote.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/misc/tpm2_checkquote.c b/tools/misc/tpm2_checkquote.c index abd09619..0c0427da 100644 --- a/tools/misc/tpm2_checkquote.c +++ b/tools/misc/tpm2_checkquote.c @@ -357,7 +357,7 @@ static bool parse_marshaled_selection_data(FILE *pcr_input, if (!file_read_bytes_from_file(pcr_input, buffer, &size, ctx.pcr_file_path)) { LOG_ERR("Failed to read PCR selection from file"); - return false; + goto error; } rc = Tss2_MU_TPML_PCR_SELECTION_Unmarshal(buffer, size, &offset, pcr_select); @@ -374,7 +374,7 @@ static bool parse_marshaled_selection_data(FILE *pcr_input, if (pcrs->count > ARRAY_LEN(pcrs->pcr_values)) { LOG_ERR("Malformed PCR file, pcr count cannot be greater than %zu, got: %" PRIu64 " ", ARRAY_LEN(pcrs->pcr_values), le64toh((UINT64)pcrs->count)); - return false; + goto error; } for (i = 0; i < pcrs->count; i++) { @@ -385,6 +385,7 @@ static bool parse_marshaled_selection_data(FILE *pcr_input, goto error; } } + free(buffer); return true; error: -- 2.54.0