jeroen / openssl

OpenSSL bindings for R
Other
63 stars 19 forks source link

Possible memory leak? #79

Open gaborcsardi opened 4 years ago

gaborcsardi commented 4 years ago

Seems like read_pubkey() leaks a bit of memory:

ps::ps_memory_info(ps::ps_handle())
#>        rss        vms    pfaults    pageins
#>   64491520 4481400832      16576        123

for (i in 1:10000) openssl::my_pubkey()
ps::ps_memory_info(ps::ps_handle())
#>        rss        vms    pfaults    pageins
#>   72728576 4482637824      18587        123

for (i in 1:10000) openssl::my_pubkey()
ps::ps_memory_info(ps::ps_handle())
#>        rss        vms    pfaults    pageins
#>   76582912 4482637824      19528        123
jeroen commented 4 years ago

I think the openssl base64 decoder is leaking a bit, but I can't see what I'm doing wrong.

jeroen commented 4 years ago

I think at least part of the problem is fixed. I'm getting this now:

> ps::ps_memory_info(ps::ps_handle())
       rss        vms    pfaults    pageins 
 164724736 4729516032      88142          0 
> #>        rss        vms    pfaults    pageins
> #>   64491520 4481400832      16576        123
> 
> for (i in 1:10000) openssl::my_pubkey()
> ps::ps_memory_info(ps::ps_handle())
       rss        vms    pfaults    pageins 
 164872192 4729516032     106147          0 
> #>        rss        vms    pfaults    pageins
> #>   72728576 4482637824      18587        123
> 
> for (i in 1:10000) openssl::my_pubkey()
> ps::ps_memory_info(ps::ps_handle())
       rss        vms    pfaults    pageins 
 164884480 4729516032     107014          0 
jeroen commented 4 years ago

Actually I cannot reproduce this with the CRAN version. For me the usage stabilizes after a while, maybe the memory from your example is just added to R's memory pool, but not lost.

Does this keep growing infinitely for you?

for(i in 1:500){
  for (i in 1:1000) openssl::my_pubkey()
  rm(list=ls()); gc()
  print(ps::ps_memory_info(ps::ps_handle()))
}

Othewise it may have to do with the version of libssl.

gaborcsardi commented 4 years ago

Yeah, it is growing, slowly.

EDIT: maybe not indefinitely....

gaborcsardi commented 4 years ago

Yeah, I think it is good.

jeroen commented 4 years ago

This would make a nice tool for spotting memory leaks btw. Where you can feed it a function, and it will repeatedly call it and show how memory usage grows over time.

gaborcsardi commented 4 years ago

IDK, it is a lot more low-tech than valgrind. :)

jeroen commented 4 years ago

Valgrind often has so many false positives that it's hard to make sense of it, and see how serious the problem is.