MALLOC problems in SCO Unix(ODT 1.0.0) -dumps core.

MALLOC problems in SCO Unix(ODT 1.0.0) -dumps core.

Post by r.. » Wed, 17 Mar 1993 21:51:43



                        Hi everobody!

It seems to very strange situation with malloc sys call in
SCO ODT 1.0.0(Unix 3.2.1) - it OFTEN dumps core in even a
very simple & apparently childish situation,like these:

1.
I define {p} as pointer to char:
char *p;
Then somewhere in programm I try to  catch some memory:
p=(char *)malloc(1);( I need only 1 byte this case,but I
had tried to request other values^when testing - no sense).
Unix immediately dumps core;
2.
I read some file by fgets. Both buffer,value of bytes to read,
& FILE pointer ARE OK. But after some succesful iteration(classic
exemple with while(fgets()!=NULL) {} - Unix again dumps core.
When I later examine the corpse with either adb or sdb - I see,
that final function called was malloc. :) . Memory amount it
(I mean malloc) requires before the death is quite reasonable.
Futhermore - even if it was too big - why use such a radical
method - it's possible just to return NULL ?

It looks like a real  BUG - doesn't it?. It makes me [sm]ad!

Any bright ideas would be appreciated.

P.S - I've just carefully read man pages on malloc - it says
it is possible to use newer version of malloc - when specifyi-
ng other library to linker by option -lmalloc.
I had done so - & now it seems to be working fine... But I still
have a question,asked above. :)

Best wishes to you.

   /=============================================================\
   | Rashid  Karimov  -  System  Administrator  of e-mail node   |
   | machine  in  Saratov, Russia.     Phone  :  8452  242491.   |
   |                      (-:*:-(                                |              
   | "To open new business just begin it. The beginning itself   |
   | is a good half of any big deal."  /Updated from Goracius /  |
   \=============================================================/

 
 
 

MALLOC problems in SCO Unix(ODT 1.0.0) -dumps core.

Post by Nikki Loc » Sun, 21 Mar 1993 04:51:50



> It seems to very strange situation with malloc sys call in
> SCO ODT 1.0.0(Unix 3.2.1) - it OFTEN dumps core in even a
> very simple & apparently childish situation,like these:

The usual reason for malloc to dump core is that the heap is already
corrupt before the call to malloc. This is usually caused by ...

1) a call to free with a pointer not returned by malloc
2) a call to free with a pointer that has already been freed
3) a stray uninitialised pointer corrupting the heap
4) overwriting beyond the bounds of an allocation

The classic example of 4 is ...

char *p = malloc(strlen(string))
strcpy(p, string);      /* oops - the '\0' terminator just trashed the heap */

--

trmphrst.demon.co.uk is NOT affiliated with ANY other sites at demon.co.uk.