Skip to content

Commit

Permalink
Easy::Operations#handle: Thread-safe cleanup (#136)
Browse files Browse the repository at this point in the history
This change fixes intermittent segfaults.
Unfortunately I don't have an easily reproducible test-case but this change seems to 
fix segfaults for a live system.
  • Loading branch information
Zapotek authored Feb 9, 2021
1 parent 1794c38 commit b4899b9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/ethon/easy/operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@ class Easy
# This module contains the logic to prepare and perform
# an easy.
module Operations

class PointerHelper
class<<self
def synchronize( &block )
(@mutex ||= Mutex.new).synchronize( &block )
end

def release( pointer )
synchronize { Curl.easy_cleanup pointer }

This comment has been minimized.

Copy link
@tagliala

tagliala May 30, 2021

Contributor

The code inside synchronize is not being executed when the release is triggered by the Garbage Collector.

More information: #194 (comment)

end
end
synchronize{}
end

# Returns a pointer to the curl easy handle.
#
# @example Return the handle.
# easy.handle
#
# @return [ FFI::Pointer ] A pointer to the curl easy handle.
def handle
@handle ||= FFI::AutoPointer.new(Curl.easy_init, Curl.method(:easy_cleanup))
@handle ||= FFI::AutoPointer.new(Curl.easy_init, PointerHelper.method(:release) )
end

# Sets a pointer to the curl easy handle.
Expand Down

1 comment on commit b4899b9

@vjt
Copy link
Contributor

@vjt vjt commented on b4899b9 May 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been identified to be root cause of #194

Please sign in to comment.