delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/09/20:33:12

From: Moo-Juice <Ben AT flag DOT demon DOT co DOT uk>
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: <ZBAaaKARLN1yEwrK@flag.demon.co.uk>
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
<zager AT post DOT comstar DOT ru> 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? <g>

-- 
Moo-Juice

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019