Module Name:    src
Committed By:   christos
Date:           Sat Mar  1 20:31:58 UTC 2025

Modified Files:
        src/lib/libc/gen: pthread_atfork.c

Log Message:
simplify af_free() (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libc/gen/pthread_atfork.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/gen/pthread_atfork.c
diff -u src/lib/libc/gen/pthread_atfork.c:1.22 src/lib/libc/gen/pthread_atfork.c:1.23
--- src/lib/libc/gen/pthread_atfork.c:1.22	Sat Mar  1 13:19:50 2025
+++ src/lib/libc/gen/pthread_atfork.c	Sat Mar  1 15:31:58 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_atfork.c,v 1.22 2025/03/01 18:19:50 christos Exp $	*/
+/*	$NetBSD: pthread_atfork.c,v 1.23 2025/03/01 20:31:58 christos Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: pthread_atfork.c,v 1.22 2025/03/01 18:19:50 christos Exp $");
+__RCSID("$NetBSD: pthread_atfork.c,v 1.23 2025/03/01 20:31:58 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -85,6 +85,7 @@ static struct atfork_callback_q childq =
 static struct atfork_callback *
 af_alloc(void)
 {
+
 	for (size_t i = 0; i < __arraycount(atfork_builtin); i++) {
 		if (atfork_builtin[i].fn == NULL)
 			return &atfork_builtin[i];
@@ -96,14 +97,12 @@ af_alloc(void)
 static void
 af_free(struct atfork_callback *af)
 {
-	for (size_t i = 0; i < __arraycount(atfork_builtin); i++) {
-		if (af == &atfork_builtin[i]) {
-			atfork_builtin[i].fn = NULL;
-			return;
-		}
-	}
-			
-	free(af);
+
+	if (af >= atfork_builtin
+	    && af < atfork_builtin + __arraycount(atfork_builtin))
+		af->fn = NULL;
+	else
+		free(af);
 }
 
 int

Reply via email to