Closed uberjay closed 4 years ago
Very nice find. I have not tried those tools myself before, but they look very useful. Maybe you'll consider writing a blog post about your hunt here.
I'm going to merge this, and will see if I am able to release a new gem.
Wow @uberjay so happy my blog post at https://samsaffron.com/archive/2019/10/08/debugging-unmanaged-and-hidden-memory-leaks-in-ruby helped out!
Free the existing entry's memory when replacing an existing entry in the environment. In the calling function (
rb_posixspawn_pspawn
), the processes' current env is duplicated; each existing environment entry is copied withstrdup
.This only occurs if
posix_spawn
is supplied with an environment hash containing keys which collide with existing keys in the environment. If that is the case, each conflicting entry's memory is leaked.This was the source of a long-standing mysterious memory growth in a few of our services. 🎉