Refactor free_n() function

Make the argument to free_n() compatible with any pointers,
thus reducing the number of compilation warnings.

End-user-impact: None
Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
Alexander Amelkin 2019-02-20 14:56:37 +03:00
parent a8b3b6282b
commit 08348f1b72
No known key found for this signature in database
GPG Key ID: E893587B5B74178D

View File

@ -37,6 +37,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> /* For free() */
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
@ -123,10 +124,12 @@ uint16_t ipmi_get_oem_id(struct ipmi_intf *intf);
* Free the memory and clear the pointer. * Free the memory and clear the pointer.
* @param[in] ptr - a pointer to your pointer to free. * @param[in] ptr - a pointer to your pointer to free.
*/ */
static inline void free_n(void **ptr) { static inline void free_n(void *ptr) {
if (ptr && *ptr) { void **pptr = (void **)ptr;
free(*ptr);
*ptr = NULL; if (pptr && *pptr) {
free(*pptr);
*pptr = NULL;
} }
} }