shithub: npe

Download patch

ref: aae3169cd7a839619bf1c43a152ebbf7489202d1
parent: 9f6cb195eca648c4aceb93ab6f1f10c902781533
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Mar 19 09:43:10 EDT 2021

sdl2: safe chanclose

--- a/libnpe_sdl2/audio.c
+++ b/libnpe_sdl2/audio.c
@@ -224,8 +224,10 @@
 	}
 	free(a->buf);
 	a->buf = nil;
-	chanfree(a->wait);
-	a->wait = nil;
+	if(a->wait != nil){
+		chanfree(a->wait);
+		a->wait = nil;
+	}
 
 	return 0;
 }
--- a/libnpe_sdl2/threads.c
+++ b/libnpe_sdl2/threads.c
@@ -29,8 +29,9 @@
 	t->userdata = data;
 	t->wait = chancreate(sizeof(int), 0);
 
-	if(proccreate(sdlthread, t, stacksz) < 0){
-		chanfree(t->wait);
+	if(t->wait == nil || proccreate(sdlthread, t, stacksz) < 0){
+		if(t->wait != nil)
+			chanfree(t->wait);
 		free(t);
 		t = nil;
 	}
@@ -47,7 +48,8 @@
 void
 SDL_DetachThread(SDL_Thread *t)
 {
-	chanclose(t->wait);
+	if(t != nil)
+		chanclose(t->wait);
 }
 
 void
@@ -55,9 +57,11 @@
 {
 	int r;
 
-	recv(t->wait, &r);
-	if(status != nil)
-		*status = r;
+	if(t != nil){
+		recv(t->wait, &r);
+		if(status != nil)
+			*status = r;
+	}
 }
 
 void