Skip to content

Commit 972ac2c

Browse files
adriansrnathany
authored andcommitted
Avoid panic when using a released CFRunLoop
As fsevents is saving the result of `CFRunLoopGetCurrent` and stopping it from a separate thread, it's necessary to increase the reference count of the returned CFRunLoopRef. In the event that the run loop is terminated by other means, `stop` might be working with a deallocated reference and produce a panic (SIGSEGV). closes #39
1 parent 0739535 commit 972ac2c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

wrap.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func (es *EventStream) start(paths []string, callbackInfo uintptr) {
225225
go func() {
226226
runtime.LockOSThread()
227227
es.rlref = CFRunLoopRef(C.CFRunLoopGetCurrent())
228+
C.CFRetain(C.CFTypeRef(es.rlref))
228229
C.FSEventStreamScheduleWithRunLoop(es.stream, C.CFRunLoopRef(es.rlref), C.kCFRunLoopDefaultMode)
229230
C.FSEventStreamStart(es.stream)
230231
close(started)
@@ -262,4 +263,5 @@ func stop(stream FSEventStreamRef, rlref CFRunLoopRef) {
262263
C.FSEventStreamInvalidate(stream)
263264
C.FSEventStreamRelease(stream)
264265
C.CFRunLoopStop(C.CFRunLoopRef(rlref))
266+
C.CFRelease(C.CFTypeRef(rlref))
265267
}

0 commit comments

Comments
 (0)