damn segmentation fault

damn segmentation fault

Post by Nathan Fege » Sat, 18 Jul 1998 04:00:00



Hi,

I am new to unix programming and I am currently working on RedHat Linux
5.1.

But anyway I'm writing a program to send out the invoices for a company
and I access a database with the program.  Anyway when I loop back
through the program I get a segmentation fault.

I ran gdb and this is what it gave me...
Program received signal SIGSEGV, Segmentation fault.
chunk_free (ar_ptr=0x400ff8a0, p=0x8053990) at malloc.c:2892
malloc.c:2892: No such file or directory.

BTW this is a C++ program...
I'm thinking this is probably not enough info for anyone to adequately
figure out what is wrong so just tell me what to send.

thanks,
nate

--
Nathan Feger

University of Pittsburgh

 
 
 

damn segmentation fault

Post by Fletcher Gle » Sat, 18 Jul 1998 04:00:00


You have included enough information.  That part is easy to say.  The
solution to your problem is not.  Any crash in one of malloc's functions
is always due to a mangled heap.  This can be done in one of the
following ways:

1. Writing outside an allocated area.
2. Free-ing the same pointer more than once.
3. Free-ing with a pointer value not supplied by malloc.

All of these are easy to say, but since the offense and the crash can
be widely separated in time, it can be fiendishly difficult to find
the problem without the aid of software designed to monitor your program
for illegal use of dynamic storage.

--
                Fletcher Glenn


>--------------87DA1DDB57209F978552F725
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit

>Hi,

>I am new to unix programming and I am currently working on RedHat Linux
>5.1.

>But anyway I'm writing a program to send out the invoices for a company
>and I access a database with the program.  Anyway when I loop back
>through the program I get a segmentation fault.

>I ran gdb and this is what it gave me...
>Program received signal SIGSEGV, Segmentation fault.
>chunk_free (ar_ptr=0x400ff8a0, p=0x8053990) at malloc.c:2892
>malloc.c:2892: No such file or directory.

>BTW this is a C++ program...
>I'm thinking this is probably not enough info for anyone to adequately
>figure out what is wrong so just tell me what to send.

>thanks,
>nate

>--
>Nathan Feger

>University of Pittsburgh

>--------------87DA1DDB57209F978552F725
>Content-Type: text/html; charset=us-ascii
>Content-Transfer-Encoding: 7bit

><HTML>
>Hi,

><P>I am new to unix programming and I am currently working on RedHat Linux
>5.1.

><P>But anyway I'm writing a program to send out the invoices for a company
>and I access a database with the program.&nbsp; Anyway when I loop back
>through the program I&nbsp;get a segmentation fault.

><P>I&nbsp;ran gdb and this is what it gave me...
><BR>Program received signal SIGSEGV, Segmentation fault.
><BR>chunk_free (ar_ptr=0x400ff8a0, p=0x8053990) at malloc.c:2892
><BR>malloc.c:2892: No such file or directory.

><P>BTW this is a C++ program...
><BR>I'm thinking this is probably not enough info for anyone to adequately
>figure out what is wrong so just tell me what to send.

><P>thanks,
><BR>nate
><BR>&nbsp;
><PRE>--&nbsp;
>Nathan Feger

>University of Pittsburgh</PRE>
>&nbsp;</HTML>

>--------------87DA1DDB57209F978552F725--


 
 
 

damn segmentation fault

Post by Christopher Schul » Sat, 18 Jul 1998 04:00:00


: I am new to unix programming and I am currently working on RedHat Linux
: 5.1.

i just installed that on my laptop, and i've been told that RH51 is a
disaster. if you can stand to do it, try downgrading to 4.2 or something.

: But anyway I'm writing a program to send out the invoices for a company
: and I access a database with the program.  Anyway when I loop back
: through the program I get a segmentation fault.

: I ran gdb and this is what it gave me...
: Program received signal SIGSEGV, Segmentation fault.
: chunk_free (ar_ptr=0x400ff8a0, p=0x8053990) at malloc.c:2892
: malloc.c:2892: No such file or directory.

okay, when you run gdb, you need to type 'where' at the prompt. this will
tell you where (duh) your program bombed. compile everything with the '-g'
flag (stick it in your makefile, or just on the command line when you type
'cc' or 'gcc').

: BTW this is a C++ program...

C++? maybe you don't want to be using malloc(). C++ people usually like to
use new(). i have no clue if they're compatable.

: I'm thinking this is probably not enough info for anyone to adequately
: figure out what is wrong so just tell me what to send.

if you can't get anything to work, then you should use your program to
tell you what's going on:

stick fprintf(stderr, "program got this far...\n") lines all over the
place.  consider using a log file for these things, too, if they become
too numerable.

every time you compare a pointer to something or try to dereference it,
test for == NULL. usually a segmentation fault comes from trying to
dereference a NULL pointer or other uninitialized pointer.

good luck,
-chris

 
 
 

damn segmentation fault

Post by Keith Moo » Mon, 20 Jul 1998 04:00:00


On 17 Jul 1998 19:40:16 GMT, Christopher Schultz



>: I am new to unix programming and I am currently working on RedHat Linux
>: 5.1.

>i just installed that on my laptop, and i've been told that RH51 is a
>disaster. if you can stand to do it, try downgrading to 4.2 or something.

  No, you just have to read the section on how the Compiler is setup.

  It explicitely explains which compiler will be used based on the program
  name you call.

  The primary problem comes from the fact that people used "gcc" as the
  C++ compiler, which they should never have done, you should always
  use g++.  In RH5.1 you should use gcc, egcs and g++ depending on what
  you want.

  RH5.1 Is a very nice release, they wanted to include egcs but did not
  want to break old non-ANSI C code, so they included the old GCC for
  C. Generally changing CC=egcs and CXX=g++ will resolve the problems
  with most Makefiles.

  This is how the compiler is setup:
  /usr/bin/cc   =gcc 2.7.2.3 (good C support)
  /usr/bin/gcc  = same as above
  /usr/bin/egcs = EGCS 1.0.2 if doing C & C++ should be used for CC
  /usr/bin/g++  = EGCS 1.0.2 should be used for C++

Quote:

>: But anyway I'm writing a program to send out the invoices for a company
>: and I access a database with the program.  Anyway when I loop back
>: through the program I get a segmentation fault.

>: I ran gdb and this is what it gave me...
>: Program received signal SIGSEGV, Segmentation fault.
>: chunk_free (ar_ptr=0x400ff8a0, p=0x8053990) at malloc.c:2892
>: malloc.c:2892: No such file or directory.

>okay, when you run gdb, you need to type 'where' at the prompt. this will
>tell you where (duh) your program bombed. compile everything with the '-g'
>flag (stick it in your makefile, or just on the command line when you type
>'cc' or 'gcc').

  If you compiled with -g for debugging, type "up" until it hits a line
  of recognizable code.

Quote:

>: BTW this is a C++ program...

>C++? maybe you don't want to be using malloc(). C++ people usually like to
>use new(). i have no clue if they're compatable.

  I believe that at the low level, in G++ they use malloc.

Quote:

>: I'm thinking this is probably not enough info for anyone to adequately
>: figure out what is wrong so just tell me what to send.

>if you can't get anything to work, then you should use your program to
>tell you what's going on:

>stick fprintf(stderr, "program got this far...\n") lines all over the
>place.  consider using a log file for these things, too, if they become
>too numerable.

>every time you compare a pointer to something or try to dereference it,
>test for == NULL. usually a segmentation fault comes from trying to
>dereference a NULL pointer or other uninitialized pointer.

>good luck,
>-chris

--
-- Keith Moore
   President
   KMA Computer Solutions, Inc.  
   Last Resort Trouble Shooting (LRTS)(tm)
 
 
 

damn segmentation fault

Post by Andrew Vicker » Mon, 20 Jul 1998 04:00:00


Quote:>every time you compare a pointer to something or try to dereference it,
>test for == NULL. usually a segmentation fault comes from trying to
>dereference a NULL pointer or other uninitialized pointer.

Maybe a good idea, when comparing for equality to constants like this, to
flip the order of the arguments:

    char *Pointer ;
    ...
    if( NULL == Pointer )
    {
        ...

It is amazing how many people accidentally use '=' instead of '=='.

This way, the compiler will barf, complaining about lvalues and your code
will be less buggy after a successful compilation.

Regards,

Andrew.

 
 
 

damn segmentation fault

Post by Ying » Tue, 21 Jul 1998 04:00:00


Quote:>Any crash in one of malloc's functions is always due to a mangled heap.

Yes, 100% agree.

Quote:>it can be fiendishly difficult to find
>the problem without the aid of software designed to monitor your program
>for illegal use of dynamic storage.

Try purify, a good tool. You'll be surprised to find how many memory leaks
and illegal memory access in your code.

Ying

 
 
 

1. Compiling *** VIM 5.3 *** Segmentation Fault..what is Seg-Fault..MEM Bounds?

Compiled fine........upgraded from 4.6  REdhat 5.0

got the src and rt of the autors VIM site via ftp.vim.org

changed the first requested by auther line in ".vimrc" file to not
read "version 4.00" and it worked once.....Gee

Now I am using it on everything ...DOS Win95 even NT40 !!!!

I know go back to the early version but still.....
what or why ...

"Segmentation Fault...Core dump"
thanks in advance.....Matt

2. NFS-Mounting on PCs

3. Page Faults/Segmentation Faults??

4. What does this Samba error mean?

5. Damn cron/xauth (or damn me)...

6. kernel: ARP: arp called for own IP address

7. Damn Mandrake! Damn rpmfind!

8. sed and NEWLINE

9. "Segmentation fault( core dumped ) "<--- sentence is driving me mad!!!!!

10. segmentation fault ?

11. Get "Segmentation fault (core dumped)" but no core file found

12. Segmentation Faults and Bus Errors

13. Dosemu0.52 : Segmentation fault?