]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Simplify and improve freep().
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 1 Sep 2019 11:41:01 +0000 (13:41 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 12 Oct 2019 15:23:45 +0000 (17:23 +0200)
Make it a no-op if NULL is passed. Also the comment to \param was
slightly incorrect and the code contained an unnecessary cast.

string.c

index 65d2240891afc81f40e6b964d5c0f6b7b25a0ddc..198e9f1d286ee2228638a2a7994fe9e65f41ccac 100644 (file)
--- a/string.c
+++ b/string.c
@@ -199,17 +199,22 @@ __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...)
 }
 
 /**
 }
 
 /**
- * Free the content of a pointer and set it to \p NULL.
+ * Free the content of a pointer and set it to NULL.
  *
  *
- * This is equivalent to "free(*arg); *arg = NULL;".
+ * \param arg A pointer to the pointer whose content should be freed.
  *
  *
- * \param arg The pointer whose content should be freed.
+ * If arg is NULL, the function returns immediately. Otherwise it frees the
+ * memory pointed to by *arg and sets *arg to NULL. Hence callers have to pass
+ * the *address* of the pointer variable that points to the memory which should
+ * be freed.
  */
 void freep(void *arg)
 {
  */
 void freep(void *arg)
 {
-       void **ptr = (void **)arg;
-       free(*ptr);
-       *ptr = NULL;
+       if (arg) {
+               void **ptr = arg;
+               free(*ptr);
+               *ptr = NULL;
+       }
 }
 
 /**
 }
 
 /**