From 772e1198dd547ca0b382be708e0e2f3668b616e2 Mon Sep 17 00:00:00 2001 From: Peter Kovary Date: Sat, 19 Jun 2021 12:55:49 +0100 Subject: [PATCH] Return error from `softPwmCreate` if `pthread_create` fails If `pthread_create` fails, `newPin` will never get reset to -1 and process would hang. This change will return from `softPwmCreate` immediately if `pthread_create` returns a non-zero value and avoid hanging forever. --- wiringPi/softPwm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wiringPi/softPwm.c b/wiringPi/softPwm.c index d99fa00..9e0aa37 100644 --- a/wiringPi/softPwm.c +++ b/wiringPi/softPwm.c @@ -153,6 +153,9 @@ int softPwmCreate (int pin, int initialValue, int pwmRange) newPin = pin ; res = pthread_create (&myThread, NULL, softPwmThread, (void *)passPin) ; + if (res != 0) + return res ; + while (newPin != -1) delay (1) ;