diff options
author | Patrick Georgi <pgeorgi@google.com> | 2019-08-27 17:18:03 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-08-28 10:13:44 +0000 |
commit | d12e6da372a33d186209154897334006efc2b42d (patch) | |
tree | 0e25d9e699513714ca10e21da9124410f226ac2b /host | |
parent | d0dae8029bc6c6805c56e384038cf8112e8766d6 (diff) | |
download | vboot-d12e6da372a33d186209154897334006efc2b42d.tar.gz |
host/lib/crossystem: free SharedData when leaving context
Minor leak avoidance as identified by Coverity Scan.
BUG=none
BRANCH=none
TEST=none
Change-Id: I4e1d0f8c7eeaf12c5cf52fb94bdcf4ed7fef3224
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1771970
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Patrick Georgi <pgeorgi@chromium.org>
Tested-by: Patrick Georgi <pgeorgi@chromium.org>
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/crossystem.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c index c8938225..061d4b71 100644 --- a/host/lib/crossystem.c +++ b/host/lib/crossystem.c @@ -103,13 +103,18 @@ int vb2_get_nv_storage(enum vb2_nv_param param) VbSharedDataHeader* sh = VbSharedDataRead(); static struct vb2_context cached_ctx; + if (!sh) + return -1; + /* TODO: locking around NV access */ if (!vnc_read) { memset(&cached_ctx, 0, sizeof(cached_ctx)); if (sh && sh->flags & VBSD_NVDATA_V2) cached_ctx.flags |= VB2_CONTEXT_NVDATA_V2; - if (0 != vb2_read_nv_storage(&cached_ctx)) + if (0 != vb2_read_nv_storage(&cached_ctx)) { + free(sh); return -1; + } vb2_nv_init(&cached_ctx); /* TODO: If vnc.raw_changed, attempt to reopen NVRAM for write @@ -118,6 +123,7 @@ int vb2_get_nv_storage(enum vb2_nv_param param) vnc_read = 1; } + free(sh); return (int)vb2_nv_get(&cached_ctx, param); } @@ -126,22 +132,30 @@ int vb2_set_nv_storage(enum vb2_nv_param param, int value) VbSharedDataHeader* sh = VbSharedDataRead(); struct vb2_context ctx; + if (!sh) + return -1; + /* TODO: locking around NV access */ memset(&ctx, 0, sizeof(ctx)); if (sh && sh->flags & VBSD_NVDATA_V2) ctx.flags |= VB2_CONTEXT_NVDATA_V2; - if (0 != vb2_read_nv_storage(&ctx)) + if (0 != vb2_read_nv_storage(&ctx)) { + free(sh); return -1; + } vb2_nv_init(&ctx); vb2_nv_set(&ctx, param, (uint32_t)value); if (ctx.flags & VB2_CONTEXT_NVDATA_CHANGED) { vnc_read = 0; - if (0 != vb2_write_nv_storage(&ctx)) + if (0 != vb2_write_nv_storage(&ctx)) { + free(sh); return -1; + } } /* Success */ + free(sh); return 0; } |