New debugging method(OT?)

V

vashwath

Probably OT, but I did not get any suitable group to discuss this as
this post also has question regarding malloc.
For my current project I am inserting the following statements
randomly.
{
int x = 0;
if (x == 1)
exit(0);
}
I can exit by setting x to 1(Using Debugger) at anytime I want.I found
that if there is any mistake in the like dynamic array overflow, The
program will exit with SIGSEGV.If there is nothing wrong with code
until exiting, the program will exit normally.I know this does not work
always, but I am able to find certain mistakes.

Now, Have a look at the following piece of code.

{
int x = 0;
if (x == 1)/*I can exit when ever I want by setting x to 1 using
debugger*/
exit(0); /*Here the program is exiting normally*/
}
some_var = malloc(some size);
{
int x = 0;
if (x == 1)
exit(0);/*Here the program is exiting with SIGSEGV*/
}

When the exit statement is executed after malloc the program is exiting
with SIGSEGV, but if the exit statement is executed just before malloc,
it is exiting normally.Does this mean there is some problem with
malloc(I don't think so:))?Or what is causing this strange behavior?

I am using gcc on Linux for compilation.
 
F

Flash Gordon

(e-mail address removed) wrote:

When the exit statement is executed after malloc the program is exiting
with SIGSEGV, but if the exit statement is executed just before malloc,
it is exiting normally.Does this mean there is some problem with
malloc(I don't think so:))?Or what is causing this strange behavior?

You are almost certainly correct in thinking malloc is *not* the
problem. The problem is almost certainly that you have gone of the end
of a buffer (either end) and overwritten some data critical to the
correct operation of malloc, thus *you* are causing malloc to fail.
However, it could be something you have done 23487972354 lines earlier.

Of course, if you had checked the comp.lang.c FAQ you would have seen
lots of information on this.

http://www.eskimo.com/~scs/C-faq/q16.8.html
http://www.eskimo.com/~scs/C-faq/q7.19.html

Lots of other questions in the FAQ apply as well.
I am using gcc on Linux for compilation.

<OT>
Try using valgrind, but don't ask for help on it here since we only deal
with standard C not all the multifarious tools that are available.
</OT>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top