Re: Code cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 31, 2000 at 03:48:37PM -0400, Federico Mena Quintero wrote:
> Maurits Rijk <lpeek.mrijk@xxxxxxxxxxx> writes:
> 
> [ ... ]
> 
> > 3) sometimes it's just lack of C knowledge:
> > 
> > 	if (p)
> > 	   free(p);
> > 
> > can be simply replaced by just: 
> > 
> > 	free(p);
> 
> If p is a null pointer then "free (p)" may (and should!) crash.  You
> are incorrect here.
> [ ... ]

  I disagree with you there. Here's an excerpt from the free(3) man page:
         free()  frees  the  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
         already been called before,  undefined  behaviour  occurs.
         If ptr is NULL, no operation is performed.
 
  It doesn't says: "If ptr is NULL, the program may crash".

                    DindinX
 

-- 
David.Odin@xxxxxxxxxxx
Author of the French Book: Programmation Linux avec GTK+

A man with one watch knows what time it is.
A man with two watches is never quite sure.


[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux