memory_utils: add close_equal() and free_equal()

parent 3d01776c
...@@ -95,4 +95,21 @@ static inline void *memdup(const void *data, size_t len) ...@@ -95,4 +95,21 @@ static inline void *memdup(const void *data, size_t len)
(a) = move_fd((b)); \ (a) = move_fd((b)); \
}) })
#define close_equal(a, b) \
({ \
if (a >= 0 && a != b) \
close(a); \
if (close >= 0) \
close(b); \
a = b = -EBADF; \
})
#define free_equal(a, b) \
({ \
if (a != b) \
free(a); \
free(b); \
a = b = NULL; \
})
#endif /* __LXC_MEMORY_UTILS_H */ #endif /* __LXC_MEMORY_UTILS_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment