1

I'm running a Perl script where everything appears to execute correctly, but it crashes immediately after calling exit 0;.

Whether I run the script normally or with perl -d, the crash still happens. However, the error messages differ:

mremap_chunk(): invalid pointer

Debug mode (perl -d):

Segmentation fault

The strange part:

  • The script logic completes successfully
  • The value from get_exit_code() is 0
  • END blocks are never executed
  • The crash happens immediately after exit is called, with no indication of Perl-level errors

What I’ve Tried:

  • Confirmed that the actual logic and output of the script is fine
  • Printed the value from get_exit_code() (custom logger module) and it returns 0
  • There are no Perl threads
  • No known unsafe DESTROY logic in my own modules
  • I'm using modules like JSON, Log::Log4perl, and others that might load XS-based components

What I’m Looking For:

  • How can I confirm if the crash is happening during global destruction?
  • Are there diagnostic techniques or Perl environment flags that can help isolate this (e.g., MALLOC_CHECK_, PERL_DESTRUCT_LEVEL)?

Any advice on how to narrow this down or fix it safely in production would be really helpful.

11
  • 2
    Your next step is to start paring away parts of the program until you have a small program that demonstrates the problem. Then you can start to narrow down what might be causing the problem. The first thing might be simply loading all the same modules, doing nothing, and letting the program exit. Commented May 13 at 11:54
  • 2
    I'd try to run it under valgrind, and I'd run it in gdb to get a stack trace (using bt) so I know where the failing code is found. Commented May 13 at 16:13
  • 1
    Of note, the word mremap_chunk is not found anywhere in the Perl code base. Commented May 14 at 12:36
  • 1
    @ikegami mremap_chunkis part of gcc/glibc, it's called during calls to realloc, if MREMAP is available. Commented May 15 at 20:55
  • 1
    @ikegami * It's tracked down to libclntshcore.so via putenv(), which clashes with %ENV cleanup in Perl * Multiple “invalid free” and “memory leak” warnings observed * Most issues stem from how Oracle Instant Client initializes environment vars (OCIEnvNlsCreate) during login We rebuilt both v1.80 and v1.90 of perl-DBD-Oracle RPM with Oracle Instant Clients 19.19, 21.x, and 23.7 — but the crash still persists on glibc-updated hosts. Commented May 16 at 13:06

1 Answer 1

3

Initially, we suspected it was entirely due to Oracle client cleanup logic during Perl's global destruction phase. However, after extensive testing and valgrind analysis, we observed that the crash only occurs on systems running a specific glibc version (2.34-125.el9_5.8), and disappears when we upgraded to glibc-2.34-168 from RHEL 9.6 Beta.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.