Generally you get std::bad_alloc when your program is unable to allocate the amount of memory requested in a call to new or new[].
This suggests a design fault in you code because on Linux you would normally expect to have a fairly large amount of memory backed by a swap disk, for example on my system I have 2 Gbyte ram backed by a 2Gbyte swap disk.
Either your program is allocating a large number of medium size chunks of memory or it is trying to allocate 1 huge chunk of memory.
Either way your design is flawed since the system wont/can't do what you have requested.
SIGSEGV (segmentation fault) is then the error produced when your program attempts to access an invalid address such as is produced by not initialising a pointer correctly because new has thrown std::bad_alloc.
You need to
- Alter your program so that it correctly handles failure to allocate memory in a graceful manor, not just through SIGSEGV and crash out even if that manor is catch the error and exit gracefully by calling abort()
- Alter your program design so that it handles its memory better and can do its job without running into failure to allocate memory.
I have only ever managed to produce a std::bad_alloc error when I have specifically written a program to continuously allocate memory until it is produced.