From: Moo-Juice Newsgroups: comp.os.msdos.djgpp Subject: Re: free() question Date: Thu, 9 Jan 1997 11:13:21 +0000 Organization: Honest Ron's Car Emporium Lines: 27 Distribution: world Message-ID: References: <32D35994 DOT 43BD AT post DOT comstar DOT ru> NNTP-Posting-Host: flag.demon.co.uk MIME-Version: 1.0 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <32D35994 DOT 43BD AT post DOT comstar DOT ru>, Dim Zegebart writes >Hi, > >Just a small question about free() function > >Let's : > >char *ptr1,*ptr2; > >ptr1=(char*)malloc(sizeof(char)*1024); >if (ptr1!=NULL) ptr2=ptr1; >... > >//so my question. May i use >free(ptr2); >//or i have to use >free(ptr1) Just use the latter, 'free(ptr1)'. As even though ptr2 has been set to ptr1, ptr1 still points to the memory block you just allocated. If you used the former, ptr1 would be NULL and ptr2 could be damn nearly anything, but you wouldn't want to free a NULL pointer would you? -- Moo-Juice