Skip to content

Commit 6498ec4

Browse files
committed
Assert that reference count is always positive.
Refcnt objects are always initialized to 1. When the counter drops to 0, the referenced object can be destroyed at any time. In refcnt_take() atomic_inc_int_nv() returns the incremented counter. That means if refs == 1, it has been 0 before. That would be a bug that should be caught. from Christian Ludwig; OK mvs@ kettenis@ a while ago
1 parent 6880dff commit 6498ec4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sys/kern/kern_synch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: kern_synch.c,v 1.226 2025/06/05 08:49:09 claudio Exp $ */
1+
/* $OpenBSD: kern_synch.c,v 1.227 2025/06/20 13:54:59 bluhm Exp $ */
22
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
33

44
/*
@@ -913,7 +913,7 @@ refcnt_take(struct refcnt *r)
913913
u_int refs;
914914

915915
refs = atomic_inc_int_nv(&r->r_refs);
916-
KASSERT(refs != 0);
916+
KASSERT(refs > 1);
917917
TRACEINDEX(refcnt, r->r_traceidx, r, refs - 1, +1);
918918
(void)refs;
919919
}

0 commit comments

Comments
 (0)