From c0c0515dd88b8b5d3fe12c05384a69a4fdc73372 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Sat, 17 Feb 2018 21:21:38 -0500 Subject: [PATCH] tpm2: Fix memory leak in VolatileLoad() Signed-off-by: Stefan Berger --- src/tpm2/StateMarshal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tpm2/StateMarshal.c b/src/tpm2/StateMarshal.c index 0f2f862..c1d384f 100644 --- a/src/tpm2/StateMarshal.c +++ b/src/tpm2/StateMarshal.c @@ -5,6 +5,7 @@ #include "tpm_library_intern.h" #include "tpm_nvfilename.h" #include "tpm_error.h" +#include "tpm_memory.h" #include "StateMarshal.h" #include "Volatile.h" @@ -24,7 +25,7 @@ VolatileLoad(void) struct libtpms_callbacks *cbs = TPMLIB_GetCallbacks(); if (cbs->tpm_nvram_loaddata) { - unsigned char *data = NULL; + unsigned char *data = NULL, *p; uint32_t length = 0; uint32_t tpm_number = 0; const char *name = TPM_VOLATILESTATE_NAME; @@ -32,11 +33,13 @@ VolatileLoad(void) ret = cbs->tpm_nvram_loaddata(&data, &length, tpm_number, name); if (ret == TPM_SUCCESS) { + p = data; rc = VolatileState_Load(&data, (INT32 *)&length); /* * if this failed, VolatileState_Load will have started * failure mode. */ + TPM_Free(p); } } #endif /* TPM_LIBTPMS_CALLBACKS */ -- 2.39.5