1
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b8bc26 in std::basic_filebuf<char, std::char_traits<char> >::_M_terminate_output() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
(gdb) where
#0  0x00007ffff7b8bc26 in std::basic_filebuf<char, std::char_traits<char>    >::_M_terminate_output() ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1  0x00007ffff7b8c6a2 in std::basic_filebuf<char, std::char_traits<char>>::close()       ()  from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#2  0x00007ffff7b8cb2a in std::basic_ofstream<char, std::char_traits<char> >::~basic_ofstream() ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x0000000000403e02 in main (argc=2, argv=0x7fffffffe1c8)
at main.cpp:630

I am facing this error after program execution and after "return 0;" has been executed.

I have used vectors from STL. This error is thrown only when input file size is very high (I am having around 10000 nodes in graph)

Also, I am not able to write output to a file. Currently I have commented that part.

Please help me with issue. I am using Ubuntu 12.10 64 bit.

  • 2
    You have probably some kind of heap corruption issue. You may try running the program under `valgrind`. – LSerni Oct 30 '12 at 01:04
  • Are you using invalidated iterators? – Kerrek SB Oct 30 '12 at 01:05
  • Do you have global objects that have destructors? That's the first thing that comes to my mind as something that gets executed *after* the final return statement. – Sergey Kalinichenko Oct 30 '12 at 01:07
  • Yes, I am using global Vectors as I will be using that generated vector in other files as well. I have only used libraries. I have not written any destructor call beside system generated. I tried the same code on windows and it works. But i need to run this on Linux only – user1784378 Oct 30 '12 at 03:11

1 Answers1

1

Errors after returning from main can be caused by (at least):

  • dodgy atexit handlers; or
  • memory corruption of some description.

Of those two, it's more likely to be the latter so you should run your code under a dynamic memory-use analysis tool, like valgrind. Your description of large vectors causing the problem also seems to support this contention.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Yes, I am using global Vectors as I will be using that generated vector in other files as well. I have only used libraries. I have not written any destructor call beside system generated. I tried the same code on windows and it works. But i need to run this on Linux only. – user1784378 Oct 30 '12 at 03:06
  • @user1784378, use a memory analysis tool as suggested. One of the most annoying features of undefined behaviour is that it _may_ work under some circumstances. If it failed always, it would be easier to find, and it wouldn't be undefined :-) – paxdiablo Oct 30 '12 at 03:12