openssl icon indicating copy to clipboard operation
openssl copied to clipboard

Possible memory leak?

Open gaborcsardi opened this issue 5 years ago • 8 comments

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

gaborcsardi avatar May 06 '20 21:05 gaborcsardi

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

jeroen avatar May 06 '20 22:05 jeroen

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 avatar May 06 '20 22:05 jeroen

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.

jeroen avatar May 06 '20 22:05 jeroen

Yeah, it is growing, slowly.

EDIT: maybe not indefinitely....

gaborcsardi avatar May 06 '20 22:05 gaborcsardi

Yeah, I think it is good.

gaborcsardi avatar May 06 '20 22:05 gaborcsardi

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.

jeroen avatar May 06 '20 23:05 jeroen

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

gaborcsardi avatar May 06 '20 23:05 gaborcsardi

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

jeroen avatar May 06 '20 23:05 jeroen