Skip to content

Commit

Permalink
Avoid stopping released CFRunLoop
Browse files Browse the repository at this point in the history
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,
`CFRunLoopStop` may be passed a deallocated reference and result in
a panic (SIGSEGV).
  • Loading branch information
adriansr committed May 2, 2018
1 parent ed9a50f commit d81ca22
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func (es *EventStream) start(paths []string, callbackInfo uintptr) {
go func() {
runtime.LockOSThread()
es.rlref = CFRunLoopRef(C.CFRunLoopGetCurrent())
C.CFRetain(C.CFTypeRef(es.rlref))
C.FSEventStreamScheduleWithRunLoop(es.stream, C.CFRunLoopRef(es.rlref), C.kCFRunLoopDefaultMode)
C.FSEventStreamStart(es.stream)
close(started)
Expand Down Expand Up @@ -266,4 +267,5 @@ func stop(stream FSEventStreamRef, rlref CFRunLoopRef) {
C.FSEventStreamInvalidate(stream)
C.FSEventStreamRelease(stream)
C.CFRunLoopStop(C.CFRunLoopRef(rlref))
C.CFRelease(C.CFTypeRef(rlref))
}

0 comments on commit d81ca22

Please sign in to comment.