From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <687643a97ce7ba1e1f4c5ab24eeb5959@coraid.com> From: erik quanstrom Date: Fri, 5 Jan 2007 09:44:06 -0500 To: 9fans@cse.psu.edu Subject: Re: [9fans] memory woes In-Reply-To: <329de470156ae34054ae5f9314a37c49@mail.gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Topicbox-Message-UUID: fdeb5e24-ead1-11e9-9d60-3106f5b1d025 you are forgetting +1 for the null. you need strlen("Hello World")+1. - erik > #include > #include > > > void main(int argc, char **argv) { > int i; > char *m00; > > for(i=0; i<=5; i++) { > if((m00 = malloc(strlen("Hello World"))) == nil) { > print("drama! [%d]\n",i); > exits("malloc"); > } > strcpy(m00,"Hello World"); > print("%d> %s\n",i,m00); > free(m00); > } > exits(nil); > }