]> diplodocus.org Git - nmh/commitdiff
Add mh_xfree(), guarding free(3) from NULLs.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 16 Oct 2016 17:21:15 +0000 (18:21 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 16 Oct 2016 17:21:15 +0000 (18:21 +0100)
Perhaps all nmh's platforms cope with free(3) these days, but it gives
symmetry with the other mh_x* memory functions and if there is code
testing the pointer before calling free then it can use this instead.

h/utils.h
sbr/utils.c

index 6a99466cb056cef20fa80cdb60788ba170910596..95cae88cff871b1f31049e158d61547faa9bb15c 100644 (file)
--- a/h/utils.h
+++ b/h/utils.h
@@ -12,6 +12,9 @@ void *mh_xrealloc(void *, size_t);
 /* Call calloc(3), exiting on NULL return. */
 void *mh_xcalloc(size_t, size_t);
 
 /* Call calloc(3), exiting on NULL return. */
 void *mh_xcalloc(size_t, size_t);
 
+/* Call free(3), if ptr isn't NULL. */
+void mh_xfree(void *ptr);
+
 char *pwd(void);
 char *add(const char *, char *);
 char *addlist(char *, const char *);
 char *pwd(void);
 char *add(const char *, char *);
 char *addlist(char *, const char *);
index 0766809d9df06c92e361ff96af0884df911f8d81..5b7b19f12b9082f8c4b280ca227a7fcf3576bf11 100644 (file)
@@ -76,6 +76,13 @@ void *mh_xcalloc(size_t nelem, size_t elsize)
     return p;
 }
 
     return p;
 }
 
+/* Call free(3), if ptr isn't NULL. */
+void mh_xfree(void *ptr)
+{
+    if (ptr)
+        free(ptr); /* Some very old platforms can't cope with NULL. */
+}
+
 /*
  * Return the present working directory, if the current directory does not
  * exist, or is too long, make / the pwd.
 /*
  * Return the present working directory, if the current directory does not
  * exist, or is too long, make / the pwd.