Fix "double free or corruption (out)"

Sometime we've seen this error when executing e.g. bundle exec rake asset:precompile:

double free or corruption (out)
rake aborted!

The reason for this can be Jemalloc. Check if you are using Jemalloc by checking the $LD_PRELOAD environment variable:

echo $LD_PRELOAD
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2

To test if Jemalloc is the reason, unset the Environment Variable and run the command again:

unset LD_PRELOAD
bundle exec rake asset:precompile

To permanently set this option in capistrano edit config/deploy.rb:

# Disable Jemalloc for asset:precompile task
set :default_env, { 'LD_PRELOAD' => '' }
Kim Klotz