delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/10/00:56:22

From: jlouwere AT galaxy DOT csc DOT calpoly DOT edu (Jan Louwerens)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: free() question
Date: 9 Jan 1997 23:30:47 GMT
Organization: Cal Poly Computer Science Dept.
Lines: 25
Message-ID: <5b3v37$e42@waldorf.csc.calpoly.edu>
References: <32D35994 DOT 43BD AT post DOT comstar DOT ru>
NNTP-Posting-Host: galaxy.csc.calpoly.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Dim Zegebart (zager AT post DOT comstar DOT ru) wrote:
: 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)

Both of them will work, however, since they both point to the same 
allocated memory block, once it is freed neither pointer should be used 
to reference (or free) the memory. (Both ptr1 and ptr2 should be set to 
null be sure).

JL

- Raw text -


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