From 55ffccfbaea62c4c8e5a69c8956441758d657eb1 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Fri, 12 Aug 2016 12:50:42 -0700 Subject: [PATCH] libpayload: cbfs: Fix minor memory leak in some edge cases cbfs_get_handle() allocates memory for a handle and doesn't free it if it errors out later, leaving the memory permanently leaked. Fix. Change-Id: Ide198105ce3ad6237672ff152b4490c768909564 Reported-by: Coverity Signed-off-by: Julius Werner Reviewed-on: https://review.coreboot.org/16207 Reviewed-by: Aaron Durbin Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel --- payloads/libpayload/libcbfs/cbfs_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/payloads/libpayload/libcbfs/cbfs_core.c b/payloads/libpayload/libcbfs/cbfs_core.c index 7e660ce83c..91f2603446 100644 --- a/payloads/libpayload/libcbfs/cbfs_core.c +++ b/payloads/libpayload/libcbfs/cbfs_core.c @@ -148,6 +148,7 @@ struct cbfs_handle *cbfs_get_handle(struct cbfs_media *media, const char *name) if (get_cbfs_range(&offset, &cbfs_end, media)) { ERROR("Failed to find cbfs range\n"); + free(handle); return NULL; } @@ -155,6 +156,7 @@ struct cbfs_handle *cbfs_get_handle(struct cbfs_media *media, const char *name) media = &handle->media; if (init_default_cbfs_media(media) != 0) { ERROR("Failed to initialize default media.\n"); + free(handle); return NULL; } } else { @@ -215,6 +217,7 @@ struct cbfs_handle *cbfs_get_handle(struct cbfs_media *media, const char *name) } media->close(media); LOG("WARNING: '%s' not found.\n", name); + free(handle); return NULL; }