Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > calloc crashing -- dump core

Reply
Thread Tools

calloc crashing -- dump core

 
 
Sheth Raxit
Guest
Posts: n/a
 
      12-04-2007
Hi

I am debugging multithreaded/netowrk prog code, It dumps core


hostname% gcc -v
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
solaris2.8/2.95.3/
specs
gcc version 2.95.3 20010315 (release)


icprg04% uname -a
SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R


====cut paste from dbx session this is ***dbx ./binary-name ./core
***
====
(dbx) thread t@65
Current function is get_remote_thick_profile
392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
(char *)NULL)
t@65 (l@65) stopped in realfree at 0xff0d4834
0xff0d4834: realfree+0x00ec: st %l0, [%i0 + %o1]
(dbx) where
current thread: t@65
[1] realfree(0xf0628, 0x400, 0x93b28, 0x494e3240, 0x0, 0xf0a3, at
0xff0d4834
[2] cleanfree(0x0, 0x10, 0x93278, 0xff139980, 0xff168284,
0xff16fad4), at 0xff0d505c
[3] _malloc_unlocked(0x8, 0x18, 0xec398, 0xec3a0, 0xffffffff,
0xfefa1000), at 0xff0d41b4
[4] malloc(0x1, 0x1, 0x94224, 0xff16fa90, 0xff168284, 0xff1709b0),
at 0xff0d40a4
[5] calloc(0x1, 0x1, 0x1, 0xff139980, 0xfefa1000, 0x1000), at
0xff0c0e68
Other Function call


Interestingly Calloc is called as below ! and it is crashing.;
392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
(char *)NULL)


What i guess is...


1. Definetly this calloc is not source of bug, but there MAY be
memory
corruption elsewhere.
2. Is this Bug ? ideally calloc should not crash like this way.
and
debugger should give me the source of real-error


--Raxit
 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      12-04-2007
Sheth Raxit wrote:
> Hi
>
> I am debugging multithreaded/netowrk prog code, It dumps core
>
>
> hostname% gcc -v
> Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
> solaris2.8/2.95.3/
> specs
> gcc version 2.95.3 20010315 (release)
>
>
> icprg04% uname -a
> SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R
>
>
> ====cut paste from dbx session this is ***dbx ./binary-name ./core
> ***
> ====
> (dbx) thread t@65
> Current function is get_remote_thick_profile
> 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> (char *)NULL)


Look again at that. And if you do not find the bug you should write 100
times:

"I should look carefully at the code"

Good handwriting required!

P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
into a char POINTER, that is probably bigger than 1 character!!!

FIX:

if (((*list) = (char *) calloc (1, sizeof (char *))) ==(char *)NULL)
^

Note the char * instead of just char?


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
 
Reply With Quote
 
 
 
 
Laurent Deniau
Guest
Posts: n/a
 
      12-04-2007
On 4 déc, 10:26, jacob navia <(E-Mail Removed)> wrote:
> Sheth Raxit wrote:
> > Hi

>
> > I am debugging multithreaded/netowrk prog code, It dumps core

>
> > hostname% gcc -v
> > Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
> > solaris2.8/2.95.3/
> > specs
> > gcc version 2.95.3 20010315 (release)

>
> > icprg04% uname -a
> > SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R

>
> > ====cut paste from dbx session this is ***dbx ./binary-name ./core
> > ***
> > ====
> > (dbx) thread t@65
> > Current function is get_remote_thick_profile
> > 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> > (char *)NULL)

>
> Look again at that. And if you do not find the bug you should write 100
> times:
>
> "I should look carefully at the code"
>
> Good handwriting required!
>
> P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
> into a char POINTER,


which is right...

T* p = (T*) calloc(1, sizeof *T);

I suspect the problem to be elsewhere.

a+, ld.
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      12-04-2007
Laurent Deniau wrote:
> On 4 déc, 10:26, jacob navia <(E-Mail Removed)> wrote:
>> Sheth Raxit wrote:
>>> Hi
>>> I am debugging multithreaded/netowrk prog code, It dumps core
>>> hostname% gcc -v
>>> Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
>>> solaris2.8/2.95.3/
>>> specs
>>> gcc version 2.95.3 20010315 (release)
>>> icprg04% uname -a
>>> SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R
>>> ====cut paste from dbx session this is ***dbx ./binary-name ./core
>>> ***
>>> ====
>>> (dbx) thread t@65
>>> Current function is get_remote_thick_profile
>>> 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
>>> (char *)NULL)

>> Look again at that. And if you do not find the bug you should write 100
>> times:
>>
>> "I should look carefully at the code"
>>
>> Good handwriting required!
>>
>> P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
>> into a char POINTER,

>
> which is right...
>
> T* p = (T*) calloc(1, sizeof *T);
>
> I suspect the problem to be elsewhere.
>
> a+, ld.


There is no *T look again. There is only sizeof(char).

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      12-04-2007
"Laurent Deniau" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
<snip>
>T* p = (T*) calloc(1, sizeof *T);

Drop the cast to not silence a possible compiler warning about a possibly
missing prototype

Bye, Jojo


 
Reply With Quote
 
Sheth Raxit
Guest
Posts: n/a
 
      12-04-2007
On Dec 4, 2:26 pm, jacob navia <(E-Mail Removed)> wrote:
> Sheth Raxit wrote:
> > Hi

>
> > I am debugging multithreaded/netowrk prog code, It dumps core

>
> > hostname% gcc -v
> > Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
> > solaris2.8/2.95.3/
> > specs
> > gcc version 2.95.3 20010315 (release)

>
> > icprg04% uname -a
> > SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R

>
> > ====cut paste from dbx session this is ***dbx ./binary-name ./core
> > ***
> > ====
> > (dbx) thread t@65
> > Current function is get_remote_thick_profile
> > 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> > (char *)NULL)

>
> Look again at that. And if you do not find the bug you should write 100
> times:
>
> "I should look carefully at the code"

I think i need to... , using for loop and printf.
>
> Good handwriting required!
>
> P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
> into a char POINTER, that is probably bigger than 1 character!!!

I am trying to allocating space for one character, and later i am
reallocating the same space.
>
> FIX:
>
> if (((*list) = (char *) calloc (1, sizeof (char *))) ==(char *)NULL)
> ^
>
> Note the char * instead of just char?

why sizeof(char *) ? return value is char* <which means pointing to
character>, which is still correct.

even we assume you are correct, why it is crashing. ?
>
> --
> jacob navia
> jacob at jacob point remcomp point fr
> logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32- Hide quoted text -
>
> - Show quoted text -


 
Reply With Quote
 
Sheth Raxit
Guest
Posts: n/a
 
      12-04-2007
On Dec 4, 2:56 pm, jacob navia <(E-Mail Removed)> wrote:
> Laurent Deniau wrote:
> > On 4 déc, 10:26, jacob navia <(E-Mail Removed)> wrote:
> >> Sheth Raxit wrote:
> >>> Hi
> >>> I am debugging multithreaded/netowrk prog code, It dumps core
> >>> hostname% gcc -v
> >>> Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
> >>> solaris2.8/2.95.3/
> >>> specs
> >>> gcc version 2.95.3 20010315 (release)
> >>> icprg04% uname -a
> >>> SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R
> >>> ====cut paste from dbx session this is ***dbx ./binary-name ./core
> >>> ***
> >>> ====
> >>> (dbx) thread t@65
> >>> Current function is get_remote_thick_profile
> >>> 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> >>> (char *)NULL)
> >> Look again at that. And if you do not find the bug you should write 100
> >> times:

>
> >> "I should look carefully at the code"

>
> >> Good handwriting required!

>
> >> P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
> >> into a char POINTER,

>
> > which is right...

>
> > T* p = (T*) calloc(1, sizeof *T);

>
> > I suspect the problem to be elsewhere.

>
> > a+, ld.

>
> There is no *T look again. There is only sizeof(char).

actually list is passed as char **list in the function.

int f1(char **list)
{
...
...

if (((*list) = (char *) calloc (1, sizeof (char))) ==(char *)NULL)
...
...
}

>
> --
> jacob navia
> jacob at jacob point remcomp point fr
> logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32- Hide quoted text -
>
> - Show quoted text -


 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      12-04-2007
Sheth Raxit said:

<snip>

> Interestingly Calloc is called as below ! and it is crashing.;
> 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> (char *)NULL)


You might find this easier to read if you write it as:

*list = calloc(1, 1);
if(*list == NULL)
{

Incidentally, does this re-write suggest anything to you about the amount
of storage you're allocating?

> What i guess is...


Guessing isn't going to help you. What is the value of list before this
allocation? Does it point to an existing char * object? If not,
dereferencing it (as you do here) is asking for trouble.


> 1. Definetly this calloc is not source of bug, but there MAY be
> memory
> corruption elsewhere.
> 2. Is this Bug ? ideally calloc should not crash like this way.
> and
> debugger should give me the source of real-error


Debuggers are not mind-readers. They're more like torches (flashlights).
They can shine a light beam for you, but it is up to you to point it in
the direction you want to see.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
vippstar@gmail.com
Guest
Posts: n/a
 
      12-04-2007
On Dec 4, 12:11 pm, Sheth Raxit <(E-Mail Removed)> wrote:
> On Dec 4, 2:56 pm, jacob navia <(E-Mail Removed)> wrote:
>
> > Laurent Deniau wrote:
> > > On 4 déc, 10:26, jacob navia <(E-Mail Removed)> wrote:
> > >> Sheth Raxit wrote:
> > >>> Hi
> > >>> I am debugging multithreaded/netowrk prog code, It dumps core
> > >>> hostname% gcc -v
> > >>> Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
> > >>> solaris2.8/2.95.3/
> > >>> specs
> > >>> gcc version 2.95.3 20010315 (release)
> > >>> icprg04% uname -a
> > >>> SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R
> > >>> ====cut paste from dbx session this is ***dbx ./binary-name ../core
> > >>> ***
> > >>> ====
> > >>> (dbx) thread t@65
> > >>> Current function is get_remote_thick_profile
> > >>> 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> > >>> (char *)NULL)
> > >> Look again at that. And if you do not find the bug you should write 100
> > >> times:

>
> > >> "I should look carefully at the code"

>
> > >> Good handwriting required!

>
> > >> P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
> > >> into a char POINTER,

>
> > > which is right...

>
> > > T* p = (T*) calloc(1, sizeof *T);

>
> > > I suspect the problem to be elsewhere.

>
> > > a+, ld.

>
> > There is no *T look again. There is only sizeof(char).

>
> actually list is passed as char **list in the function.
>
> int f1(char **list)
> {
> ...
> ...
>
> if (((*list) = (char *) calloc (1, sizeof (char))) ==(char *)NULL)
> ...
> ...
>
> }


Please post a minimal test case that demonstrates your problem.

That function could be valid if used like this:
--
char *p;
f1(&p);
--
But invalid if used like this
--
char **p;
f1(p);
--

Also, decide what language you're using, and if you find the problem
to be somewhere outside of standard C code post in an appropriate
newsgroup
 
Reply With Quote
 
Laurent Deniau
Guest
Posts: n/a
 
      12-04-2007
On 4 déc, 10:56, jacob navia <(E-Mail Removed)> wrote:
> Laurent Deniau wrote:
> > On 4 déc, 10:26, jacob navia <(E-Mail Removed)> wrote:
> >> Sheth Raxit wrote:
> >>> Hi
> >>> I am debugging multithreaded/netowrk prog code, It dumps core
> >>> hostname% gcc -v
> >>> Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
> >>> solaris2.8/2.95.3/
> >>> specs
> >>> gcc version 2.95.3 20010315 (release)
> >>> icprg04% uname -a
> >>> SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R
> >>> ====cut paste from dbx session this is ***dbx ./binary-name ./core
> >>> ***
> >>> ====
> >>> (dbx) thread t@65
> >>> Current function is get_remote_thick_profile
> >>> 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> >>> (char *)NULL)
> >> Look again at that. And if you do not find the bug you should write 100
> >> times:

>
> >> "I should look carefully at the code"

>
> >> Good handwriting required!

>
> >> P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
> >> into a char POINTER,

>
> > which is right...

>
> > T* p = (T*) calloc(1, sizeof *T);


oups:

T* p = (T*) calloc(1, sizeof *p);

> > I suspect the problem to be elsewhere.

>
> > a+, ld.

>
> There is no *T look again. There is only sizeof(char).


s/\*T/\*p/

still, if T is char, *p is of type char, then sizeof(char) is ok.

a+, ld.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dump complete java VM state as core dump (not via OS) possible? halfdog Java 12 02-21-2013 06:14 AM
Core Solo & Core Duo are not Core microarchitecture; 65nm Pentium M chips bigal Hardware 0 03-22-2006 11:24 AM
Cisco AP1200 core dump B Thompson Cisco 7 11-26-2005 03:59 AM
Read Core Dump file ns Cisco 8 05-26-2005 03:07 AM
jvm core dump with jni c++ on AIX only Mike Java 0 12-09-2003 05:15 PM



Advertisments