[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: [LI] free...



Hi,
	The linux man page says:
		"free(ptr) frees memory space pointed to by ptr, which
must have been returned by a previous call to malloc, calloc or
realloc. Otherwise, or if free(ptr) has been called before, undefined
behaviour occurs. If ptr is NULL, no operation is performed".

If you want to see how malloc() and free() are implemented, 
look up K&R section 8.7, page 185. It is worth the read!

If ptr is the only variable containing the address of the malloced block
and you do ptr=NULL before calling free(ptr), you are creating a 
potential memory leak. 

						regards,
						pramode.

 

On Tue, 25 Jan 2000, Arun K Desai wrote:

> Hi all,
> What "free" does???
> Suppose i am having a pointer say *ptr.
> If say free(ptr) what it does???
> If say  ptr=NULL what it does???
> Is it both are same????
> 
>                      Regards,
>                        Arun.
> 
> 
> LYCOShop. Thousands of products!  One location!
> http://shop.lycos.com/
> --------------------------------------------------------------------
> The Linux India Mailing List Archives are now available.  Please search
> the archive at http://lists.linux-india.org/ before posting your question
> to avoid repetition and save bandwidth.
> 

--------------------------------------------------------------------
The Linux India Mailing List Archives are now available.  Please search
the archive at http://lists.linux-india.org/ before posting your question
to avoid repetition and save bandwidth.