Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There's a memory leak problem in Curl::Easy.download #240

Closed
liudangyi opened this issue Mar 20, 2015 · 5 comments
Closed

There's a memory leak problem in Curl::Easy.download #240

liudangyi opened this issue Mar 20, 2015 · 5 comments

Comments

@liudangyi
Copy link

I use the following code.

photos.each do |photo|
  filename = "../thumbs/#{photo[:id]}.jpeg"
  Curl::Easy.download(photo[:thumb_url], filename) unless File.exist? filename
end

And it quickly (about 50M/s) eats up my memory.

@daedric
Copy link

daedric commented Oct 30, 2015

This path would probably fix it but since the current master segfault on my laptop I will not create a pull request

diff --git a/ext/curb_multi.c b/ext/curb_multi.c
index db9a35a..281ff52 100644
--- a/ext/curb_multi.c
+++ b/ext/curb_multi.c
@@ -68,7 +68,7 @@ rb_hash_clear_i(VALUE key, VALUE value, VALUE dummy) {

 static void curl_multi_free(ruby_curl_multi *rbcm) {

-  if (rbcm && !rbcm->requests == Qnil && rb_type(rbcm->requests) == T_HASH && RHASH_SIZE(rbcm->requests) > 0) {
+  if (rbcm && !NIL_P(rbcm->requests) && rb_type(rbcm->requests) == T_HASH && RHASH_SIZE(rbcm->requests) > 0) {

     rb_hash_foreach( rbcm->requests, (int (*)())curl_multi_flush_easy, (VALUE)rbcm );

@taf2
Copy link
Owner

taf2 commented Nov 2, 2015

Thanks for finding this definitely looks like a bug... and your patch makes good sense. looking into why it is now causing a segfault in your example

@taf2
Copy link
Owner

taf2 commented Nov 2, 2015

Do you have a sample test case I can run to repeat the crash?

@taf2
Copy link
Owner

taf2 commented Dec 17, 2015

I believe this is fixed now in 0.9.0 please confirm.

@taf2 taf2 closed this as completed Dec 17, 2015
mkauf added a commit to mkauf/curb that referenced this issue Apr 8, 2016
This fixes the segmentation fault that has been mentioned in issue taf2#240 (introduced with commit 50ab567).
taf2 pushed a commit that referenced this issue Apr 8, 2016
This fixes the segmentation fault that has been mentioned in issue #240 (introduced with commit 50ab567).
@HolyWalley
Copy link

HolyWalley commented Oct 27, 2021

As I can see it's not fixed

curb (0.9.11)

puts "MEMORY USAGE: %d MB" % (`ps -o rss= -p #{Process.pid}`.to_i / 1024)
=> MEMORY USAGE: 107 MB

Curl::Easy.download(direct_link_to_large_file)

puts "MEMORY USAGE: %d MB" % (`ps -o rss= -p #{Process.pid}`.to_i / 1024)
=> MEMORY USAGE: 139 MB

in my case file size was 32MB which is eq to difference in memory, so, I suppose it's been loaded into memory somewhere.

I experimented with file on our corporate s3, so, can't share direct link here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants