From c431b358c802e1ec207ecbf3f68c34e9b2a17f46 Mon Sep 17 00:00:00 2001 From: Florian La Roche Date: Fri, 7 Jun 2024 10:17:13 +0200 Subject: [PATCH] event_create(): check malloc() return value to be non-NULL (#1084) * event_create(): check malloc() to be non-NULL Check malloc() to return non-NULL before writing data in the function event_create(). Signed-off-by: Florian La Roche * Code review suggestion Signed-off-by: Gaurav Aggarwal --------- Signed-off-by: Florian La Roche Signed-off-by: Gaurav Aggarwal Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Co-authored-by: Gaurav Aggarwal --- portable/ThirdParty/GCC/Posix/utils/wait_for_event.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c b/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c index beca2b360..bf744e27f 100644 --- a/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c +++ b/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c @@ -43,9 +43,13 @@ struct event * event_create( void ) { struct event * ev = malloc( sizeof( struct event ) ); - ev->event_triggered = false; - pthread_mutex_init( &ev->mutex, NULL ); - pthread_cond_init( &ev->cond, NULL ); + if( ev != NULL ) + { + ev->event_triggered = false; + pthread_mutex_init( &ev->mutex, NULL ); + pthread_cond_init( &ev->cond, NULL ); + } + return ev; }