Project

General

Profile

Actions

Bug #18409

closed

Crash (free(): invalid pointer) if LD_PRELOAD doesn't explicitly include libjemalloc.so.2

Added by itay-grudev (Itay Grudev) almost 3 years ago. Updated over 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]
[ruby-core:106686]

Description

I recently installed Ruby 3.0.2 using rbenv with:

RUBY_CONFIGURE_OPTS='--with-jemalloc' rbenv install 3.0.2

After running our app it always crashed with:

free(): invalid pointer
[1]    51364 IOT instruction (core dumped)  bundle exec rails assets:precompile

I also tried upgrading to 3.0.3 with no success.

After researching the bug a lot and lots of failed attempt to track it down I stumbled upon this report: https://github.com/grpc/grpc/issues/25450 that recommended trying:

LD_PRELOAD=$LD_PRELOAD:/lib/x86_64-linux-gnu/libjemalloc.so.2 bundle exec rails assets:precompile

That seems to have worked, but that can't be the proper solution in production. Surely it shouldn't be required.

Updated by xtkoba (Tee KOBAYASHI) almost 3 years ago

Seems like someone (who?) is calling libc free() directly, maybe?

Updated by itay-grudev (Itay Grudev) almost 3 years ago

How can I try to trace it? I tried attaching GDB to the process with little success.

Updated by xtkoba (Tee KOBAYASHI) almost 3 years ago

I noticed that 737e4432b978eb4b9f5b10fb6cc6d9c883a5d17a is not backported to Ruby 3.0.x series. So before ./configure you may need to do something like

export LDFLAGS="-Wl,--no-as-needed"

Make sure that the ruby executable has DT_NEEDED entry for libjemalloc.so:

$ readelf -Wa ruby | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libruby.so.3.1]
 0x0000000000000001 (NEEDED)             Shared library: [libz.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libjemalloc.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libgmp.so.10]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libcrypt.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libbacktrace.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

Updated by jeremyevans0 (Jeremy Evans) almost 3 years ago

  • Status changed from Open to Closed
  • Backport changed from 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: REQUIRED

Since it looks like this is fixed in the master branch, closing and marking for backport to Ruby 3.0 (not sure if it is needed on Ruby 2.7).

Updated by nagachika (Tomoyuki Chikanaga) over 2 years ago

  • Backport changed from 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: REQUIRED to 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: DONE

ruby_3_0 09b27ec6a984ec1b660d5b7b48f2ff4d5a0065bc merged revision(s) 737e4432b978eb4b9f5b10fb6cc6d9c883a5d17a.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0