How to detect segfaults out of memory?

How to determine if segfault occurs due to lack of memory?

I have a segfault that challenges the diagnosis of valgrind and duma / efence because it seems to destroy these tools itself (Valgrind "the possibleibe happens", duma: "mprotect () failed: cannot allocate memory")

The app (Gazebo) just crashes with segfault and a stack trace that doesn't seem to give a lot of clues about why.

TL; DR: Is there a simple tool or method to confirm or exclude due to lack of memory reasons for segfault?

(the top one does not show an excessive amount of memory usage before the crash)

+1
source share
1 answer

On Linux, a low memory condition can occur in one of two ways:

  • If overcommit is disabled, the call to brk() or mmap() ends with ENOMEM . Shortly afterwards, the application tries to dereference the NULL pointer returned from malloc() and crash.
  • If overcommit is enabled, then the OOM killer starts and kills the process using SIGKILL. Message sent to dmesg.

This way you can exclude OOM by indicating that strace does not show brk() or mmap() calls with an ENOMEM error and checks that OOM killer messages are not displayed in dmesg.

+5
source

Source: https://habr.com/ru/post/1261888/


All Articles