shithub: front

Download patch

ref: b356fcb216746620daa7007b00830f506850bd38
parent: 8d435d074683b347eec263504986af2afa471276
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);
--