git: 9front

Download patch

ref: 58aab38c3b28721181dd2b181bc5999ae30df1f2
parent: 20e6629f9c75fb44d03a927eda9fd047b608849d
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Jun 8 15:50:12 EDT 2025

kernel: re-check Segment.ref whend detaching from Image

Oversight from previous commit. We really need
to re-check the Segment.ref while holding Image.Lock
of we'r cached by an Image, as the reference can drop
to 0 between our decref() in putseg() and acquirering
the Image lock (someone grabbing a ref from Image cache).

--- a/sys/src/9/port/segment.c
+++ b/sys/src/9/port/segment.c
@@ -99,6 +99,10 @@
 	i = s->image;
 	if(i != nil) {
 		lock(i);
+		if(s->ref != 0){
+			unlock(i);
+			return;
+		}
 		if(i->s == s)
 			i->s = nil;
 		putimage(i);
--