Segmentation error after major returns

I have a long program in c over Linux that gives me a segmentation error after major returns. This is a long program, so I cannot publish it. So can you help me what such a mistake can do?

Thanks.

Wow, these answers came very quickly. Thank you all. I think I processed this, I forgot the malloc string and used it as a buffer. Now that I have done this, it does not signal a segmentation error to me.

Thanks again to everyone.

+3
source share
4 answers

Guess: you can accidentally damage the stack in the main so that it loses the return address. Do you have a string buffer that could be bypassed?

If not, you should try:

  • running the program under valgrind
  • debugging a program using gdb to catch a crash and see where you are; you can also debug the main file dumped

This can help install glibc-debug packages if you have their distribution, since you will be in glibc code at that point.

+3
source

Use GDB tracing and stack traces on the SIGSEGV signal. Then at least write that so that we can be a little more useful.

If you compiled with:

$ gcc -g prog.c -o prog 

Then run it under gdb:

 $ gdb ./prog gdb> r 

When you receive a SIGSEGV (segmentation error) signal, do the following:

 gdb> bt 

Then look at what's on the stack trace to see what causes the segmentation error.

+1
source

If a segmentation error occurs after returning main (), this usually means that the global specific thing went wrong. It is hard to help you with such little information. Send us more information!

my2c

+1
source

If it returns after main() , then, in accordance with the standard, all destructors were started (although I would not have missed the implementation to wash it a bit), unless the atexit() function was used. This function registers a function that will be called after main() returns, efficiently (if I read 3.6.3). You can check if your program has atexit , if only for completeness.

Depending on what you mean by โ€œafter major returnsโ€, you can run destructors for static objects when the program crashes. Check them out. (Also post what you notice, making you think you might be wrong after returning main() .)

If not, then you called undefined behavior somewhere, it is very likely that you somehow damaged the stack. See Rup Answer for suggestions.

+1
source

All Articles