From f5afc5c7773123e397161c7decc03aeaf38b26f6 Mon Sep 17 00:00:00 2001 From: Andrey Pronin Date: Fri, 27 Sep 2019 15:17:15 -0700 Subject: cr50: nvmem: release var buf in setvar overflow case Before this CL, if overflow condition was detected for an existing variable, the buffer allocated by find_var() was not released. This CL fixes this issue. BRANCH=none BUG=b:141774483 TEST=running test_nvmem with CL:1828184 applied doesn't lead to memory leaks. Change-Id: Ie09561232a613fb1f90f9a9456af73106ceb44ff Signed-off-by: Andrey Pronin Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1829291 Reviewed-by: Vadim Bendebury Commit-Queue: Jason Clinton --- common/new_nvmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'common/new_nvmem.c') diff --git a/common/new_nvmem.c b/common/new_nvmem.c index fee15a3fc0..e61021e3c3 100644 --- a/common/new_nvmem.c +++ b/common/new_nvmem.c @@ -2934,8 +2934,10 @@ static int setvar_(const uint8_t *key, uint8_t key_len, const uint8_t *val, if ((old_var_space < new_var_space) && ((total_var_space + new_var_space - old_var_space) > - MAX_VAR_BODY_SPACE)) + MAX_VAR_BODY_SPACE)) { + shared_mem_release(vc); return EC_ERROR_OVERFLOW; + } /* Save the new instance first with the larger generation number. */ vc->c_header.generation++; -- cgit v1.2.1