From aca6cf402b3c46f6cb055cf5475597987c377356 Mon Sep 17 00:00:00 2001 From: Tasos Laskos Date: Tue, 14 Feb 2017 23:05:07 +0200 Subject: [PATCH 1/4] Easy::Operations#handle: Thread-safe cleanup 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. --- lib/ethon/easy/operations.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/ethon/easy/operations.rb b/lib/ethon/easy/operations.rb index 43702f4..c3f2a1c 100644 --- a/lib/ethon/easy/operations.rb +++ b/lib/ethon/easy/operations.rb @@ -3,6 +3,20 @@ class Easy # This module contains the logic to prepare and perform # an easy. module Operations + + class PointerHelper + class< Date: Mon, 10 Jan 2022 21:30:07 +0200 Subject: [PATCH 2/4] Ethon::Easy#handle: Add proc for cleanup --- lib/ethon/easy/operations.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ethon/easy/operations.rb b/lib/ethon/easy/operations.rb index a3c0185..3176b7c 100644 --- a/lib/ethon/easy/operations.rb +++ b/lib/ethon/easy/operations.rb @@ -25,7 +25,8 @@ def release( pointer ) # # @return [ FFI::Pointer ] A pointer to the curl easy handle. def handle - @handle ||= FFI::AutoPointer.new(Curl.easy_init, PointerHelper.method(:release) ) + # @handle ||= FFI::AutoPointer.new(Curl.easy_init, PointerHelper.method(:release) ) + @handle ||= FFI::AutoPointer.new(Curl.easy_init, proc { |pointer| Curl.easy_cleanup(pointer) }) # works for me end # Sets a pointer to the curl easy handle. From 4313c5a0d02f4bd90a2101eedaa95ac4288c332e Mon Sep 17 00:00:00 2001 From: Tasos Laskos Date: Tue, 25 Jan 2022 17:05:02 +0200 Subject: [PATCH 3/4] Ethon::Easy#handle: Removed old commented out code --- lib/ethon/easy/operations.rb | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/lib/ethon/easy/operations.rb b/lib/ethon/easy/operations.rb index 3176b7c..b8714e0 100644 --- a/lib/ethon/easy/operations.rb +++ b/lib/ethon/easy/operations.rb @@ -4,20 +4,6 @@ class Easy # This module contains the logic to prepare and perform # an easy. module Operations - - class PointerHelper - class< Date: Tue, 25 Jan 2022 17:05:42 +0200 Subject: [PATCH 4/4] Ethon::Easy#handle: Added explanation for proc cleanup --- lib/ethon/easy/operations.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ethon/easy/operations.rb b/lib/ethon/easy/operations.rb index b8714e0..e06af52 100644 --- a/lib/ethon/easy/operations.rb +++ b/lib/ethon/easy/operations.rb @@ -11,6 +11,7 @@ module Operations # # @return [ FFI::Pointer ] A pointer to the curl easy handle. def handle + # Use proc for cleanup to avoid segfaults. @handle ||= FFI::AutoPointer.new(Curl.easy_init, proc { |pointer| Curl.easy_cleanup(pointer) }) end