macro: check existence of cleanup function before call it

The free function specified in the macro may be provided by a
dynamically loaded library.

Replaces #25781.
This commit is contained in:
Yu Watanabe
2022-12-19 21:07:39 +09:00
committed by Lennart Poettering
parent 80ce8580f5
commit 9c29d87bee

View File

@@ -64,10 +64,14 @@
_Pragma("GCC diagnostic push")
#endif
#define DISABLE_WARNING_TYPE_LIMITS \
#define DISABLE_WARNING_TYPE_LIMITS \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wtype-limits\"")
#define DISABLE_WARNING_ADDRESS \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Waddress\"")
#define REENABLE_WARNING \
_Pragma("GCC diagnostic pop")
@@ -318,10 +322,14 @@ static inline int __coverity_check_and_return__(int condition) {
*p = func(*p); \
}
/* When func() doesn't return the appropriate type, set variable to empty afterwards */
/* When func() doesn't return the appropriate type, set variable to empty afterwards.
* The func() may be provided by a dynamically loaded shared library, hence add an assertion. */
#define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(type, func, empty) \
static inline void func##p(type *p) { \
if (*p != (empty)) { \
DISABLE_WARNING_ADDRESS; \
assert(func); \
REENABLE_WARNING; \
func(*p); \
*p = (empty); \
} \