]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
macro: check existence of cleanup function before call it
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 19 Dec 2022 12:07:39 +0000 (21:07 +0900)
committerLennart Poettering <lennart@poettering.net>
Thu, 22 Dec 2022 09:59:26 +0000 (10:59 +0100)
The free function specified in the macro may be provided by a
dynamically loaded library.

Replaces #25781.

src/basic/macro.h

index 3d1b1751231b995979150617b636df9931c2b9bd..a00d60824dd1249bdea44f410c928407f2ffb3c2 100644 (file)
         _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);                           \
                 }                                               \