Re: [cc65] Need some help with a memory leak

From: Spiro Trikaliotis <ml-cc651trikaliotis.net>
Date: 2010-05-05 20:59:40
Hello Johan,

* On Wed, May 05, 2010 at 12:57:09AM +0200 Johan Kotlinski wrote:
> > if(currentNode->dir_entry != NULL)
> > {
> >    free(currentNode->dir_entry);
> > }
> 
> One suggestion: You could remove this unnecessary NULL check. free()
> does nothing when passed a null pointer.

But what if anyone wants to compile the code with a pre-ANSI compiler?

Naw, just kidding.

However, personally, I still prefer the free() with a check. It tells me
that some thought has been done by the programmer that the pointer might
be zero. ("Wrong code should look wrong.")

Only if I am really sure the pointer cannot be NULL, I write it without
the if. Additionally, I prefer something like an assert() to ensure this
through debugging, and again, telling a reader of my code that I
considered this.

Of course, you are right, free() is required to be a no-op for NULL
pointers since 1989. However, this is not true for every function. Why
should we distinguish between them? It only makes it harder to find out
that something is wrong.

(Now, don't look at any of my code and tell me: "But there, you did it
differently." Yes, I know it. My personal taste and coding style changes
from different factors over the time.)

Regards,
Spiro.

-- 
Spiro R. Trikaliotis                              http://opencbm.sf.net/
http://www.trikaliotis.net/                     http://www.viceteam.org/
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Wed May 5 20:59:52 2010

This archive was generated by hypermail 2.1.8 : 2010-05-05 20:59:55 CEST