From 94e73f6f0cef2c419540633bdf359b7035ac9ccf Mon Sep 17 00:00:00 2001 From: Florian La Roche Date: Thu, 6 Jun 2024 21:36:02 +0200 Subject: [PATCH 1/2] 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 --- portable/ThirdParty/GCC/Posix/utils/wait_for_event.c | 9 ++++++--- 1 file changed, 6 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 beca2b360e..40a428df0d 100644 --- a/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c +++ b/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c @@ -43,9 +43,12 @@ 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 ) + { + ev->event_triggered = false; + pthread_mutex_init( &ev->mutex, NULL ); + pthread_cond_init( &ev->cond, NULL ); + } return ev; } From cba502370b9cb7a1c4d15d0b05ff9cc5082bac67 Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Fri, 7 Jun 2024 08:04:13 +0000 Subject: [PATCH 2/2] Code review suggestion Signed-off-by: Gaurav Aggarwal --- portable/ThirdParty/GCC/Posix/utils/wait_for_event.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c b/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c index 40a428df0d..bf744e27f3 100644 --- a/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c +++ b/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c @@ -43,12 +43,13 @@ struct event * event_create( void ) { struct event * ev = malloc( sizeof( struct event ) ); - if( ev ) + if( ev != NULL ) { ev->event_triggered = false; pthread_mutex_init( &ev->mutex, NULL ); pthread_cond_init( &ev->cond, NULL ); } + return ev; }