nvfile: Free allocated memory on failure

In TPM_NVRAM_LoadData(), there is an unlikely path where the function
will return an error code but still expect the caller to free the
allocated data. At least some of the callers don't handle this correctly
so ensure that the caller only needs to free data if the function
returns success.

Reported by Coverity.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
This commit is contained in:
Ross Lagerwall 2022-05-20 12:00:57 +01:00 committed by Stefan Berger
parent f9a6f51cb8
commit 71d3a27bc7

View File

@ -267,6 +267,11 @@ TPM_RESULT TPM_NVRAM_LoadData(unsigned char **data, /* freed by caller */
printf(" TPM_NVRAM_LoadData: Closed file %s\n", filename);
}
}
if (rc) {
free(*data);
*data = NULL;
}
return rc;
}