[PATCH 14/32] bthread: fix null pointer dereference in error path

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Sep 5 02:55:39 PDT 2022


When borting bthread creation early, we would end up calling
bthread_free on a NULL bthread, causing a NULL pointer dereference.

As it's customary for free functions to gracefully handle a NULL
argument, have bthread_free follow suit.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/bthread.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/common/bthread.c b/common/bthread.c
index 46e6987149bb..d40c0b0f9e3a 100644
--- a/common/bthread.c
+++ b/common/bthread.c
@@ -70,6 +70,8 @@ bool bthread_is_main(struct bthread *bthread)
 
 static void bthread_free(struct bthread *bthread)
 {
+	if (!bthread)
+		return;
 	free(bthread->stack);
 	free(bthread->name);
 	free(bthread);
-- 
2.30.2




More information about the barebox mailing list