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.
valgrind, and I'd run it ingdbto get a stack trace (usingbt) so I know where the failing code is found.mremap_chunkis not found anywhere in the Perl code base.mremap_chunkis part of gcc/glibc, it's called during calls torealloc, ifMREMAPis available.