tests/lib/memset-test: Add missing malloc check and free on error

Coverity found resource leak in test setup function in error block.
Add malloc result check and free in error handling to silence Coverity.

Signed-off-by: Jakub Czapiga <jacz@semihalf.com>
Found-by: Coverity CID 1446760
Change-Id: Icf746df27167047fa3cf8f5df09fced20863f76d
Reviewed-on: https://review.coreboot.org/c/coreboot/+/54874
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
This commit is contained in:
Jakub Czapiga 2021-05-24 13:33:07 +02:00 committed by Felix Held
parent d2b2a18307
commit 5ab67f9ef8
1 changed files with 2 additions and 2 deletions

View File

@ -16,10 +16,9 @@ struct memset_test_state {
static int setup_test(void **state) static int setup_test(void **state)
{ {
struct memset_test_state *s = malloc(sizeof(struct memset_test_state)); struct memset_test_state *s = malloc(sizeof(struct memset_test_state));
u8 *buf = malloc(MEMSET_BUFFER_SZ); u8 *buf = malloc(MEMSET_BUFFER_SZ);
u8 *helper_buf = malloc(MEMSET_BUFFER_SZ); u8 *helper_buf = malloc(MEMSET_BUFFER_SZ);
if (!buf || !helper_buf) if (!s || !buf || !helper_buf)
goto error; goto error;
s->base_buffer = buf; s->base_buffer = buf;
@ -31,6 +30,7 @@ static int setup_test(void **state)
error: error:
free(buf); free(buf);
free(helper_buf); free(helper_buf);
free(s);
return -1; return -1;
} }