Skip to content

Commit 3893400

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
fix: extract remove() to keep deferred unlock in HandleStore.Release
1 parent 3c0147b commit 3893400

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

handlestore/handlestore.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,21 @@ func (s *HandleStore) Release(env *jni.Env, handle int64) {
6262
if handle == 0 {
6363
return
6464
}
65+
obj := s.remove(handle)
66+
if obj != nil {
67+
env.DeleteGlobalRef(obj)
68+
}
69+
}
70+
71+
// remove atomically deletes a handle from the map and returns the object.
72+
func (s *HandleStore) remove(handle int64) *jni.Object {
6573
s.mu.Lock()
74+
defer s.mu.Unlock()
6675
obj, ok := s.objects[handle]
6776
if ok {
6877
delete(s.objects, handle)
6978
}
70-
s.mu.Unlock() // Unlock before JNI call to avoid holding the mutex during DeleteGlobalRef.
71-
if ok {
72-
env.DeleteGlobalRef(obj)
73-
}
79+
return obj
7480
}
7581

7682
// Len returns the number of active handles.

0 commit comments

Comments
 (0)