onetrueawk / awk

One true awk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unnecessary Check For Non-NULL Pointer Before free(3) Call

ldo opened this issue · comments

The xfree macro checks that the pointer is non-NULL before calling free(3). This is unnecessary. From the man page:

 If ptr is NULL, no operation is performed.

As a general principle, I like to give all my object-freeing routines the same behaviour.

diff --git a/awk.h b/awk.h
index cc30249..ccd16c9 100644
--- a/awk.h
+++ b/awk.h
@@ -37,7 +37,7 @@ typedef double    Awkfloat;

 typedef    unsigned char uschar;

-#define    xfree(a)    { if ((a) != NULL) { free((void *)(intptr_t)(a)); (a) = NULL; } }
+#define    xfree(a)    { free((void *)(intptr_t)(a)); (a) = NULL; }
 /*
  * We sometimes cheat writing read-only pointers to NUL-terminate them
  * and then put back the original value

thanks, this is a good catch.