sbrk(2) question

Boyd Roberts boyd at necisa.ho.necisa.oz.au
Fri Mar 15 11:14:25 AEST 1991


In article <4312 at skye.ed.ac.uk> richard at aiai.UUCP (Richard Tobin) writes:
|While experimenting, I was reminded of another hazard of sbrk().  For
|example, this program produces a segmentation fault on a Sun4 under
|SunOS 4.1:
|
|    #include <stdio.h>
|    
|    extern char *sbrk();
|    
|    main()
|    {
|        sbrk(100000);
|        printf("hello world\n");
|        sbrk(-100000);
|        printf("hello again\n");
|        exit(0);
|    }

Well, I thought everybody new that sbrk(2) and malloc(3) just
don't mix.  Odds on printf(3) calls malloc and gets some memory
whose address is > sbrk(0) + 100000*.  The second printf references
this memory after the second sbrk and it's length violation city!

malloc(3) and sbrk(2) -- be careful out there.


Boyd Roberts			boyd at necisa.ho.necisa.oz.au

``When the going gets wierd, the weird turn pro...''

* Obviously rounded up to the next page.



More information about the Comp.unix.questions mailing list