Permalink
Browse files

Fix a memory leak in Easy

This commit fix an issue in Easy when the method is :post. The params
were garbage collected, especially with a large number of requests. The
params are now copied to libCURL, so we're sure we won't leak any more,
even if the referenced objects are GC.

This refer to the libcurl doc:

"CURLOPT_POSTFIELDS
...
The pointed data are NOT copied by the library:
as a consequence, they must be preserved by the calling application
until the transfer finishes.  "

We're now using :

"CURLOPT_COPYPOSTFIELDS
...
Pass a char * as parameter, which should be the
full data to post in an HTTP POST operation. It behaves as the
CURLOPT_POSTFIELDS option, but the original data are copied by the
library, allowing the application to overwrite the original data after
setting this option.  "
  • Loading branch information...
1 parent 4657cbf commit 32531d0821aecc42b39774c76c5a6fde46ae868e @gravis gravis committed Jul 3, 2010
Showing with 2 additions and 2 deletions.
  1. +2 −2 lib/typhoeus/easy.rb
@@ -12,6 +12,7 @@ class Easy
:CURLOPT_UPLOAD => 46,
:CURLOPT_CUSTOMREQUEST => 10036,
:CURLOPT_POSTFIELDS => 10015,
+ :CURLOPT_COPYPOSTFIELDS => 10165,
:CURLOPT_POSTFIELDSIZE => 60,
:CURLOPT_USERAGENT => 10018,
:CURLOPT_TIMEOUT_MS => 155,
@@ -50,7 +51,6 @@ class Easy
def initialize
@method = :get
- @post_dat_set = nil
@headers = {}
set_option(OPTION_VALUES[:CURLOPT_ENCODING], 'zlib') if supports_zlib?
@@ -158,8 +158,8 @@ def method=(method)
def post_data=(data)
@post_data_set = true
- set_option(OPTION_VALUES[:CURLOPT_POSTFIELDS], data)
set_option(OPTION_VALUES[:CURLOPT_POSTFIELDSIZE], data.length)
+ set_option(OPTION_VALUES[:CURLOPT_COPYPOSTFIELDS], data)
end
def params=(params)

0 comments on commit 32531d0

Please sign in to comment.