aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Child <nnac123@gmail.com>2021-04-21 16:05:45 -0400
committerVasant Hegde <hegdevasant@linux.vnet.ibm.com>2021-06-24 17:02:16 +0530
commit980780586b6fcb43a5d92361181ff72be89e7283 (patch)
treed16131a563ceeecbbd8494f039ed763f5407eb5f
parente35b9fac10532dda79a8d96d32c4eeff8b718b48 (diff)
downloadskiboot-980780586b6fcb43a5d92361181ff72be89e7283.zip
skiboot-980780586b6fcb43a5d92361181ff72be89e7283.tar.gz
skiboot-980780586b6fcb43a5d92361181ff72be89e7283.tar.bz2
secvar/secvar_util: Properly free memory on zalloc fail
[ Upstream commit e964b78d567fab5263ed339c89516039a8714295 ] If allocating the secure variable name of a secure variable struct, `secvar->key`, fails then the secvar struct should be freed before returning NULL. Previously, if this allocation fails, then only the `secvar->key` is freed (which is likely a typo) leaving the allocated `secvar` struct allocated and returning NULL. This memory leak can be seen with the static analysis tool `cppcheck`. After running valgrind tests, this commit ensures that memory is properly freed if an error occurs when allocating the `key` field of the `secvar` struct. Signed-off-by: Nick Child <nick.child@ibm.com> Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
-rw-r--r--libstb/secvar/secvar_util.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/libstb/secvar/secvar_util.c b/libstb/secvar/secvar_util.c
index 533170a..d14a9a5 100644
--- a/libstb/secvar/secvar_util.c
+++ b/libstb/secvar/secvar_util.c
@@ -49,7 +49,7 @@ struct secvar *alloc_secvar(uint64_t key_len, uint64_t data_size)
ret->key = zalloc(key_len);
if (!ret->key) {
- free(ret->key);
+ free(ret);
return NULL;
}