Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!utgpu!attcan!telly!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Newsgroups: comp.lang.c Subject: Re: malloc/free question Message-ID: <1990May3.135327.28940@druid.uucp> Date: 3 May 90 13:53:27 GMT References: <2638831C.728C@telly.on.ca> <1990Apr28.020711.8639@druid.uucp> <6822@jarthur.Claremont.EDU> Reply-To: darcy@druid.UUCP (D'Arcy J.M. Cain) Organization: D'Arcy Cain Consulting, West Hill, Ontario Lines: 35 In article <6822@jarthur.Claremont.EDU> dfoster@jarthur.Claremont.EDU (Derek R. Foster) writes: >In article <1990Apr28.020711.8639@druid.uucp> darcy@druid.UUCP (D'Arcy J.M. Cain) writes: >>Well I have never seen the source for a malloc and I don't know how it is >>normally done but a moment's thought will suggest that the above can't work. >>Consider the following: >> char *ptr = malloc(64); >> strcpy(ptr, "Stomp on the malloc structure"); >> free(ptr); > >Wellllll.... not necessarily. >Remember, malloc usually allocates a few more bytes than you ask it to. >The extra info could be stored at the beginning of the structure Here is the original suggestion I was responding to: