executable causing core

Hi,

One of my executables is coring. I tried to debug the core using gdb. I got the following stack trace:-

gdb reconProcess core

> Wildebeest is free software and you are welcome to distribute copies

> of it under certain conditions; type "show copying" to see the

> conditions.

> There is absolutely no warranty for Wildebeest; type "show warranty"

> for details.

>

> Hewlett-Packard Wildebeest 1.0 (based on GDB 4.16) (built for PA-RISC

> 1.1 or 2.0 (narrow), HP-UX 11.00) Copyright 1996, 1997 Free Software

> Foundation, Inc...

> Core was generated by `reconProcess'.

> Program terminated with signal 11, Segmentation fault.

>

> warning: The shared libraries were not privately mapped; setting a

> breakpoint in a shared library will not work until you rerun the

> program.

>

> #0 0xc0198090 in _sigfillset () from /usr/lib/libc.2 #0 0xc0198090

> in _sigfillset () from /usr/lib/libc.2

> (gdb) bt

> #0 0xc0198090 in _sigfillset () from /usr/lib/libc.2

> #1 0xc0195bbc in _sscanf () from /usr/lib/libc.2

> #2 0xc019b294 in malloc () from /usr/lib/libc.2

> #3 0x1eb60 in stradd (dest=0x77ff1f48, src=0x403dddac "0") at

> aogutils.cpp:24

> #4 0x2d534 in AOG_Action::fcifTo (this=0x403ddd40)

>at /cm41/rel41/rel/bgp/interfaces/aog/AOGActionRecon.cpp:5363

> #5 0x18fd4 in AOG_Order::FCIF4VDN (this=0x4009e560, target=1001) at

> AOGOrderRecon.cpp:1955

> #6 0x1865c in AOG_Order::AddVDN (this=0x4009e560) at

> AOGOrderRecon.cpp:1729

> #7 0x1470c in AOG_ROrder::buildFCIF (this=0x4009e560, custID=135714)

> at AOGOrderRecon.cpp:479

> #8 0x115ac in processRecon (Tn=@0x77ff1178, Oe=@0x4032f108)

>at /cm41/rel41/rel/bgp/interfaces/aog/reconProcess.cpp:445

> #9 0x123f8 in tnType (Num=0x77ff08d8 " 1") at

> /cm41/rel41/rel/bgp/interfaces/aog/reconProcess.cpp:605

> #10 0xe0b0 in main (argc=5, argv=0x77ff060c) at

> /cm41/rel41/rel/bgp/interfaces/aog/reconProcess.cpp:310

> (gdb)

From the stack trace, it seems that there is a problem in the stradd function where it makes a call to malloc(). The following is the code for function stradd():-

/*CODE - stradd()*/

// This funciton adds src to dest

void stradd( char **dest, const char *src )

{

char *tmp;

if( src == NULL )

return;

if( *dest == NULL )

{

tmp = (char *)[b]malloc[/b]( strlen( src ) + 1 );

strcpy( tmp, src );

}

else

{

tmp = (char *)malloc( strlen( *dest ) + strlen( src ) + 1 );

strcpy( tmp, *dest );

strcat( tmp, src );

free(*dest);

}

*dest = tmp;

}

The Highlighted malloc call seems to be giving a problem.

Could anyone help me out.

Thanks in Advance.

[3041 byte] By [ravi_m] at [2007-11-26 8:22:09]
# 1
It's rather hard to make malloc crash. I notice that there's [b]_sscanf[/b] function call from malloc (why would malloc need sscanf?). Can this be the real problem?
MaximKartashev at 2007-7-6 21:29:53 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

Actually, malloc will often crash in the presence of programming errors that corrupt the heap, such as

- use of an invalid or uninitialized pointer

- deleting an object more than once

- deleting a pointer value that was not obtained from the allocator

- using an object after it has been deleted or gone out of scope

- failure to guard the use of shared data in a multi-threaded program

Any of these errors can wind up corrupting the data structures used by malloc and free. A call to malloc or free after the corruption has occurred can cause the crash -- usually far away in space and time from the location of the error.

If you use Sun Studio tools, you can turn on Run-Time Checking in the dbx debugger, which will find many of these errors at the point where they occur.

You can download Sun Studio 11 free on this web page:

http://developers.sun.com/sunstudio

clamage45 at 2007-7-6 21:29:53 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

Have a quick look at this:

> Hewlett-Packard Wildebeest 1.0 (based on GDB 4.16) (built for PA-RISC

> 1.1 or 2.0 (narrow), HP-UX 11.00) Copyright 1996, 1997 Free Software

> Foundation, Inc...

You're posting questions about HP-UX issues to a Sun Studio development list...

r1mikey at 2007-7-6 21:29:53 > top of Java-index,Development Tools,Solaris and Linux Development Tools...